You can take schedule backup with shell script. Firstly, You must create shell script file in operating system. After you can append to crontab.
Crontab is a UNIX command that creates a table or list of commands, each of which is to be executed by the operating system at a specified time. crontab is used to create the crontab file (the list) and later used to change the previously created crontab file.
crontab -e Edit your crontab file, or create one if it doesn’t already exist.
crontab -l List your crontab file.
crontab -r Remove your crontab file.
crontab -v Display the last time you edited your crontab file.
Minute Hour Day of Month Month Day of Week Command
(0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
0 2 12 * 0,6 /usr/bin/shellscriptname.sh
We will take backup wirh pg_dumpall. Firstly, You must create shell script.
Note : We created shellscriptname.sh with vi shellscriptname.sh statement. You have to write below script.
export today=`date +%Y%m%d`
export deleteday=`/bin/date –date=”15 days ago” +%Y%m%d`
##delete old backup script
rm -f /tmp/pgalldump_$deleteday.dump.out
##create backup script
pg_dumpall > /tmp/pgalldump_$today.dump.out
Note : After write, You close editor with ” escape > :wq! > enter “. You saved.
We wrote shell script. Now, We have to append to crontab.
10 1 * * * /etc/scripts/shellscriptname.sh
Note : After write, You close editor with ” escape > :wq! > enter “. You saved. This time statement mean that shell script will execute every days of week,every month, every day, at 1 hour past 10 minute.
5,858 total views, 5 views today