How to backup your webserver files and mysql database using

I am very happy with my provider, but if you don’t have backup server for your account, you need another service to backup your files.

After a little research, i found Their price is acceptable ($0.80-1.4 gb/mounth | static - global redundant) , and the service is really fine.

I want to backup my dbs every night, but files; every two weeks. My model is like this:

  1. Backup every database individually to /mybackups/db
  2. Backup every vhost folder individually /mybackups/vhosts
  3. Than mount filesystem to the webserver
  4. Syncronize local backup folder to the mounted filesystem

Here is how i setup my server.

You need to install sshfs to your server first, than

sudo apt-get install sshfs

due to a bug, run below code

sudo modprobe fuse

If rsync is not installed

sudo apt-get install rsync

After you make your purchase from, they will send you an email regarding to your account information. I choosed tp pay with paypal and subscribed, so it will be paid monthly.

We are going to use automated scripts, so, it is better to use ssh keys. If you haven’t created your ssh key already, do it:

ssh-keygen -t rsa

Do not enter a pass phrase, just hit enter twice.

Now we need to send it to the server. Type something like this:

scp ~/.ssh/ [email protected]:.ssh/authorized_keys

Of course change [email protected] with your user info.

To backup my databases i use this bashscript (

### MySQL Server Login Info ###
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
GZIP="$(which gzip)"
MOUNT="/mnt/your-rsync-backup-folder" #name whatever you want
find $BAK -type d -mtime +30 -exec rm -rf {} \; #delete anything older than 30 days. you can change this one whatever you want.
NOW=$(date +"%d-%m-%Y")
mkdir $BAK/$NOW
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
 FILE=$BAK/$NOW/$db.$NOW-$(date +"%T").gz
sshfs [email protected]: $MOUNT
rsync -az --delete --force --stats /your/backup/path $MOUNT
fusermount -u $MOUNT

Now save it wherever you want (not under anywhere web accesible!) and change its writing permissions to 755

To backup my files ( i use something like this

# check whether the job runned last week
if [ -e $mark_file ] ; then
  rm -f $mark_file
  touch $mark_file
  exit 0
#above part is for only to run this script once in two weeks
MOUNT="/mnt/your-rsync-backup-folder" #name same as the above one
find $BAK -type d -mtime +46 -exec rm -rf {} \; #delete anything older than 46 days. since we backup our files every two weeks, we will have 4 versions of each
NOW=$(date +"%d-%m-%Y")
mkdir $BAK/$NOW
for files in *
set $files
OF=$BAK/$NOW/$1-$NOW-$(date +"%T").tar.gz
#echo $OF
tar -czvf $OF $files
done # exiting for loop
unset $files # un setting set variables
sshfs -o nonempty [email protected]: $MOUNT
rsync -az --delete --force --stats /your/backup/path $MOUNT
fusermount -u $MOUNT
exit 0 # exiting shell script

Save this file like the other one and change write permission of course.

Now we need to tell the machine to run these scripts automatically. Type

crontab -e

At the end of the file add these lines and press kntrl+o and enter (i mean save it)

01 02 * * * /your/path/to/
01 03 * * 7 /your/path/to/ 

First line will execute the db bash script every day at 02:01 am, the second one execute files bash script every sunday at 03:01, but the file control in the script cause it to run only once in two weeks.

I think that’s all. If you face any problems, feel free to let me know.