Backups Setup 2: Electric Boogaloo

We have written briefly before about backups and their importance which, again, cannot be overstated. You may heard a saying like ‘there are two kinds of sys admins: those that made backups and those that don't have a job anymore.'

Anyway, when it comes to backups you also need to validate them to be sure that they saved correctly and that it's what you wanted to save. I can remember a few cases when I suddenly realized that a directory was moved to another location a while ago, but the backup routine was still backing up from the old location. Of course, I ended up noticing only when I had to restore the data. The moral here is that you should be thinking about your backups at the same time that you're thinking about your primary files, or it will bite you sooner or later. 

Let’s go back to the example we used in our last article and restore the backups we made before. We set up backup of your ‘/var/www’ directory in the file ‘www.tar.gz’ as you can see below:

[root@serversuit ~]# ls /backups/ -g –h
-rwxr-xr-x 1 root   49 May 13 15:16
-rw-r--r-- 1 root 111M May 13 15:18 www.tar.gz
If you accidently delete one or more files in that directory you can run the command:
tar -xkf www.tar.gz

You will have the ‘/backups/var/www’ directory, and you can manually copy all needed files to the original ‘/var/www’ directory. It’s the safest way to restore only the files that you need. There are also a few improvements we can make to the backup script we created last time. At the moment, you’d have one daily backup archive which will be rewritten every time you run the script. This is the improved script:

tar -cvf /backups/www-$(date + %Y-%m-%d).tar.gz /var/www/
mysqldump –u root -pPASSWORD DATABASE > /backups/dump-$(date + %Y-%m-%d).sql

With this new code, the backup will create daily archives like shown below:

[root@serversuit ~]# ls /backups/ -g –h
-rwxr-xr-x 1 root  127 Jun  1 21:55
-rw-r--r-- 1 root 115M Jun  4 22:00 www-2016-06-04.tar.gz
-rw-r--r-- 1 root 114M Jun  3 22:00 www-2016-06-03.tar.gz
-rw-r--r-- 1 root 113M Jun  2 22:00 www-2016-06-02.tar.gz
-rw-r--r-- 1 root 430K Jun  4 22:00 dump-2016-06-04.sql
-rw-r--r-- 1 root 429K Jun  3 22:00 dump-2016-06-03.sql
-rw-r--r-- 1 root 428K Jun  2 22:00 dump-2016-06-02.sql'

The last thing you’ll need to do is add the cleanup script to remove old backup files from the directory:

	find /backups/*.gz -mtime +7 -exec rm -f {} \;

You can add that to your cron jobs to remove all archives older than 7 days. Last thing we need to discuss is how to restore your MySQL backups. You have files like ‘dump-2016-06-04.sql’ with the backup of your database. If you have to restore your database from the backup you will run the following commands:

	[root@serversuit ~]# mysql -uroot -pPASSWORD < /backups/dump-2016-06-04.sql

WARNING: make sure that your backup data contains valid data! Current database tables will be deleted during restore! It’s a good idea to make the backup of the current database so you can return to it if your backup is not properly configured.

As you could see already, backing up and restoring your server data isn't that simple, and requires some forethrought and preparation.
You can’t just setup and forget – you’ll need to keep track of changes to data, storage space requirements, backup file consistency, etc.

Fortunately, ServerSuit can help you do that!
You can configure backup of all your Linux server data in just under a minute!

Let me show you how to do that.
I just created a test user with some domain, FTP access, MySQL database and cron jobs and I can make a full backup of that user data with a single click:

You can restore all of your data in the‘Restore backup’ tab like shown below:


Click ‘Full-Account Restore’ and choose ‘Restore backup’ option from drop-down list:


As long as your Linux server is being managed through ServerSuit, you won't have to worry about backups past the initial setup. Our service is still in Beta, so watch for scheduled and automated backups, as well as partial restore, features being included in future releases!

Hope this helped you a little with backup setups. Be sure to follow us on Twitter and Facebook to stay updated with future articles.

Until next time!

June 06 2016

Add or review comments

Please leave your comment

Existing comments

Comments 0