Basics Of Setting Up A Backup On Linux

Every system administrator should know that server backups are necessary and they must be configured so soon as possible. One of the first things you're taught as an IT professional. And yet every day another unlucky soul ends up with corrupted or deleted data, because the server hanged or the hard disk broke and suddenly realized that they forgot to setup a backup. Sounds familiar? I hope not, but almost everyone ends up in that place, eventually. Lett's at least try not to repeat these mistakes.

So, today, let me show you the basics of setting up a backup on your Linux system. Let’s assume that you’ have a website on your server, and you want to have a backup copy on the same server somewhere, and you'll probably will want to send it to another computer, too. We’ll need to create a backup directory, and we'll use the following scripts:

[root@serversuit ~]# mkdir /backups [root@serversuit ~]# nano /backups/make_backup.sh #!/bin/sh tar -cvzf /backups/www.tar.gz /var/www [root@serversuit ~]# nano /backups/make_backup.sh [root@serversuit ~]# chmod +x /backups/make_backup.sh [root@serversuit ~]# /backups/make_backup.sh [root@serversuit ~]# ls /backups/ -g –h -rwxr-xr-x 1 root 49 May 13 15:16 make_backup.sh -rw-r--r-- 1 root 111M May 13 15:18 www.tar.gz

If we add this script to cron to run daily, you’ll always have the current site's HTML files backed up to the server's /backup directory. You can download it to another computer, too. What if your website is not just HTML or PHP files, but MySQL database files too? There's a slightly altered script to do that as well:

[root@serversuit ~]# nano /backups/make_backup.sh #!/bin/sh tar -cvzf /backups/www.tar.gz /var/www mysqldump –u root -pPASSWORD DATABASE > /backups/dump.sql

You’ll need to provide the root password and database name to make script work. Please be aware that your MySQL database backup can take a long time and significantly increase server load. That script can be used for relatively small databases, but it should probably be run overnight to avoid overloading your server. This is the script you'll need to add the backup to cron and run it overnight:

[root@serversuit ~]# crontab -e 0 3 * * * /backups/make_backup.sh

This will run a script ‘make_backup.sh’ once a day at 3am, overwriting old backup files. It’s not too hard at all... just time consuming, especially in cases where you have multiple servers or websites.



But hey, that's why we built ServerSuit.

We can help with that too. We have a preconfigured backup tool you can easily setup on your servers with just a few clicks, and no coding requires. Use it to safely backup your domains, MySQL databases, and FTP folders. You can access your server backups through ServerSuit's browser dashboard. Try it out! ServerSuit is free for 30-days when you first sign up! Check us out!



Until next time!