Scripting Features:
System environment: SUSE Linux Server 11.3 X64
1. Delete compressed files (. bak.tar.gz) 3 days ago
2. Back up the database (uncompressed file. bak)
3. Compress yesterday database backup file (. bak.tar.gz), delete yesterday database backup uncompressed file (. 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 {} \;
This article is from the "Yiyi" blog, make sure to keep this source http://heyiyi.blog.51cto.com/205455/1658896
PostgreSQL backup script deleted 3 days ago Backup while compressing yesterday backup