Skip to content

Automatic Backup Scripts

This assumes that you have 2 Linux machines / servers – one to backup to the other.

To enable the script to automatically login to the destination server you will need to enabled ssh key based logins.

First off, create an SSH Key on the server.

ssh-keygen -t dsa

Hit enter for all questions.

Run the following command to send the key to the backups server (you will need to enter the password manually)
cat ~/.ssh/ | ssh "cat - >> .ssh/authorized_keys"

Save the script below into /root/ and set it executeable (chmod +x

# Backup Script
# Tim Igoe 2007
# Usage - ./

NOW=`date +”%d-%m-%Y”`



GZIP=`which gzip`
SCP=`which scp`
RM=`which rm`

mysqldump -u backup –password=secure_password –all-databases > $DB

tar -cpf $FILES $WWWROOT

# Zip it all up

# Transfer it to backup server
$SCP $DB.gz$DB.gz

$RM $DB.gz

Then finally, set a cron to run nightly / weekly / monthly

crontab -e

# Weekly Server Backup
0 5 * * 6 cd /root/; ./

Published inServers

Be First to Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.