Simple & Cool backup script

Here is a cool script, used to backup this site and a few others hosted here. The script should be self explanatory.

#!/bin/sh

# First, archive the older backups.
for file in public_html mail database.mysql; do
for number in 6 5 4 3 2 1 ; do
  if [ -f "$HOME"/backup/"$file"."$number".tar.gz ] ; then
   mv "$HOME"/backup/"$file"."$number".tar.gz "$HOME"/backup/"$file".$(($number + 1)).tar.gz
  fi
done
if [ -f "$HOME"/backup/"$file".tar.gz ] ; then
  mv "$HOME"/backup/"$file".tar.gz "$HOME"/backup/"$file".1.tar.gz
fi
done

# Now create new backups for files.
cd $HOME
tar -czf $HOME/backup/public_html.tar.gz public_html
tar -czf $HOME/backup/mail.tar.gz mail

# And create new backups for mysql.
for database in database ; do
mysqldump -u username -ppassword "$database" > "$HOME"/backup/"$database".mysql && tar -czf "$HOME"/backup/"$database".mysql.tar.gz backup/"$database".mysql
rm "$HOME"/backup/"$database".mysql
done

Some modifications have been made for publishing, not to reveal to much information...

Comments

Thanks for the idea. I'll be

Thanks for the idea. I'll be using this in my project. - Fred Wehba

About Consultancy Articles Contact




References Red Hat Certified Architect By Robert de Bock Robert de Bock
Curriculum Vitae By Fred Clausen +31 6 14 39 58 72
By Nelson Manning [email protected]