vi /backups/postgre_backup.sh
#!/bin/bash
date1=`date +%d%m%Y_%H%M%S`
export path1=/backups/postgre_backup
OUTPUTDIR="$path1/$date1"
/usr/bin/find /backups/postgre_backup/* -type d -mtime +32 -exec rm -r {} \; 2> /dev/null
su postgres -c 'pg_dumpall' > "$OUTPUTDIR.sql"
/bin/tar -zcvf /backups/postgre_backup/ backup_$date1.tar.gz $OUTPUTDIR.sql
rm $OUTPUTDIR.sql
exit
date1=`date +%d%m%Y_%H%M%S`
export path1=/backups/postgre_backup
OUTPUTDIR="$path1/$date1"
/usr/bin/find /backups/postgre_backup/* -type d -mtime +32 -exec rm -r {} \; 2> /dev/null
su postgres -c 'pg_dumpall' > "$OUTPUTDIR.sql"
/bin/tar -zcvf /backups/postgre_backup/
rm $OUTPUTDIR.sql
exit
:wq
Schedule in crontab:-
# crontab -e
0 0 * * * /backups/postgre_backup.sh > /dev/null
# crontab -e
0 0 * * * /backups/postgre_backup.sh > /dev/null
No comments:
Post a Comment