postgreSQL備份指令碼刪除3天前備份同時壓縮昨天備份

來源:互聯網
上載者:User

標籤:postgresql shell

指令碼功能:

系統內容:SUSE Linux Server 11.3 X64

1.刪除3天前壓縮檔(.bak.tar.gz)

2.備份資料庫(未壓縮檔.bak)

3.壓縮昨天Database Backup檔案(.bak.tar.gz),刪除昨天Database Backup未壓縮檔(.bak)


#!/bin/bash

export PATH=$PATH:/usr/local/pgsql/bin

DATE=`date +%Y_%m_%d_%H`

YESDAY=`date -d "yesterday" +%Y_%m_%d_%H`

TWODAGO=`date -d "3 day ago" +%Y_%m_%d_%H`

PGHOME="/home/postgres"

cd $PGHOME


echo "Dir list before delete 3 day ago backup file: "

ls -lrt


#### delete 3 day ago backup file ####

TDAFILE="testdb_"$TWODAGO".bak.tar.gz"

echo "Detele 3 Day ago file: "$TDAFILE

rm "$TDAFILE"

echo "Dir list after delete 3 day ago backup file: "

ls -lrt


#### Backup ape database ####


echo $DATE

echo "Starting backup database: ape ...."

su - postgres -c "pg_dump testdb > /home/postgres/testdb_$DATE.bak"

reval=#?

if reval=0

then 

echo "Database testdb backup Successful!"

else

echo "Database testdb backup Failed!"

fi


echo "Dir list After backup database testdb: "

ls -lrt


#### Compress and remove yesterday bak file####

COMFILE="testdb_"$YESDAY".bak.tar.gz"

YDFILE="testdb_"$YESDAY".bak"

echo "tar zcvf $COMFILE $YDFILE"|sh 

echo "General yesterday tar file: "$COMFILE

rm "$YDFILE"

echo "delete yesterday file: "$YDFILE

echo "Dir list After tar yesterday backup file: "

ls -lrt


find /home/postgres -mtime +3 -name "*.bak" -exec rm -rf {} \;

find /home/postgres -mtime +3 -name "*.bak.tar.gz" -exec rm -rf {} \;


本文出自 “yiyi” 部落格,請務必保留此出處http://heyiyi.blog.51cto.com/205455/1658896

postgreSQL備份指令碼刪除3天前備份同時壓縮昨天備份

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.