I have a very limited experience with shell scripting and would like to put in place some sort of script that backs up my blog (Wordpress) on a weekly basis.
Here is what I have so far
#!/bin/bash
# Determine current date
setenv CURDATE date +%Y%m%d
# Backup DB & email it to me
mysqldump dbname -u user -ppassword | gzip | uuencode ${CURDATE}dbname.sql.gz | mail -s "backup for dbname ${CURDATE}" my@email.com
cd /home/myhome
# Zip blog
tar cf - blog.mysite.me | gzip - > ~/backups/${CURDATE}blog.mysite.me.tar.gz
And this is where I am a bit stuck... I was thinking about emailing myself the blog directory but what happens when this becomes bigger then 10MB or so? how would I script this to split this and email me the chunks?
Another suggestion I have which I feel is better is to FTP the backups to another VPS that I own. But for the sake of space I would like to only keep the last 10 backups. How would I implement the part of the script script that:
- Upload backup
- Get list of files
- Gets count of files in the current dir (e.g. /home/myhome/backups/blog )
- If count > 10 delete oldest
Any help/advice or pointers with solving this problem would be much appreciated :)