Linux Config Backup Script Andrew Mallett | Updated June 2017

Data should always be kept separate (slice, partition) from system files and should be backed up regularly. Additionally server configuration files for the operating system and various applications also need to be backed up, in case the server goes belly-up or a new server needs to be built.

Fortunately Unix makes it easy, as everything is just a file and they're all clear text. Using the following script I can back up my entire gateway server config's in 10 seconds, to a remote system and they take up 100Kb of space. Compare that to a Windows Server..

So here's the script. Click inside the iframe and press CTRL A to highlight the code and then copy and paste..

There's a fair bit of fluff there to make it run pretty but basically the script uses Samba to mount a network share, waits for 10 in case the remore file server is busy, creates a new directory based on the current date and time and then copies all the files across to subdirectories. A couple of variables $start and $stop are used to indicate the total backup time.

Note that the cd command is important before the umount at the end, as the script initially changes to the remote directory for the copying. If the script doesn't cd out back to some directory on the local server (in this case root's home), then the script won't be able to unmount the share.

Andy's Configs..

The configs don't change much so I run the whole thing manually from a custom menu, whenever something changes.

And yes, I did write this script after getting caught out. The hard disk died on a Linux Server and although it was quick and easy to reinstall the OS, particularly with the archived configs, I had to rewrite my conky config file, which was extensively customised but not backed up.

100Kb in 10 seconds, f**k I love Unix..

If you're really keen, why not automate the script using cron..