Website and database back-up shell script
We assume in this little article that you want to make some back-ups but you don’t want super sophisticated scripts and stuffy things to roll on your machine. More than that we assume that you want to make a folder back-up and also a mysql database back-up. If you need something like that, here are some simples yet efficient ideas:
1 2 3 4 5 6 7 8 9 10 |
#!/bin/bash MAIL=`which mutt` DATE=`date +%d-%m-%y` FILE=site_archive_$DATE SOURCE=/home/username/htdocs DESTINATION=/home/username/backup/$FILE ZIPFILE=$DESTINATION.zip tar -cf $DESTINATION $SOURCE 2> /dev/null zip $ZIPFILE $DESTINATION $MAIL -a $ZIPFILE -s "The archive for $DATE" email@domain.com < /dev/null |
That’s it.
If you want a database back-up script then just modify the source above like this:
1 2 3 |
FILE=db_archive_$DATE.sql SOURCE=/home/username/$FILE DATABASE=`mysqldump -u username -ppassword --opt database > $SOURCE` |
Even more you can copy your files to a different location using scp like this:
1 2 |
# file transfer scp $ZIPFILE user@host:/your/remote/path |
You can also transfer a full folder:
1 2 |
# folder transfer scp -r your_local_folder user@host:/your/remote/path |
If you have question leave a comment.
Enjoy!

















thanks man. it was really helpful. i’ll be back