Setting up logging for a remote backup script
Posted
by
Brian Dainis
on Server Fault
See other posts from Server Fault
or by Brian Dainis
Published on 2012-11-02T06:06:25Z
Indexed on
2012/11/02
23:04 UTC
Read the original article
Hit count: 207
So I wrote up a short script that I am planning to run via a cron job daily to package up my site files and send them to a remote location. I also plan to incorporate DB dumps, but I have not gotten that far yet.
My issue today however is that Im am uncertain how to log the output of each command for errors, warnings, or other pertinent information the command may output. I would also like to install sometype of fail safe so if something goes horribly wrong the script will stop dead in its tracks and notify me via email or something. Ok the email thing is not as critical, but would be nice.
Does anybody have any ideas for that? Here is what I have so far.
By the way, both servers are CentOS 6.2 running standard LAMP.
#!/bin/sh
#################################
### Set Vars
#################################
THEDATE=`date +%m%d%y%H%M`
#################################
### Create Archives
#################################
tar -cf /root/backups/files/server_BAK_${THEDATE}.tar -C / var/www/vhosts
gzip /root/backups/files/server_BAK_${THEDATE}.tar
#################################
### Send Data to Remote Server
#################################
scp /root/backups/files/server_BAK_${THEDATE}.tar.gz user@host:/home/bak1/ftp/backups/
#################################
### Remove Data from this Server
#################################
rm -rf /root/backups/files/server_BAK_${THEDATE}.tar.gz
© Server Fault or respective owner