It is always useful to be able to automate backups. I found some of this out there in the ether and use it often.

#!/bin/bash
dir="/var/www";
# what directory or file to back up
cd ${dir}
 
if [[ $? != 0 ]]; then
   #cd failed, we'll exit with an error message
   echo "Error: could not cd to ${dir}. No backup was created."
   exit 1;
fi;
 
# path to back up folder
tar -zcf /var/www/backups/backup-$(date +%Y%m%d).tar.gz .
Google Buzz
  • Share/Bookmark