Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


# 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}"

cd /home/myhome

# Zip blog
tar cf - | gzip - > ~/backups/${CURDATE}

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:

  1. Upload backup
  2. Get list of files
  3. Gets count of files in the current dir (e.g. /home/myhome/backups/blog )
  4. If count > 10 delete oldest

Any help/advice or pointers with solving this problem would be much appreciated :)


merged by sysadmin1138 Apr 19 '11 at 20:22

This question was merged with Simple bash backup solution because it is an exact duplicate of that question.

Browse other questions tagged or ask your own question.