- Basic Linux tutorials for beginner
- Linux basic concepts, installation and troubleshooting
- Linux administration
- Linux commands
- Linux network tutorials
- Linux security tutorials
- Linux software configuration
- Linux desktop tutorials for beginner
- Collection of Linux tips
Linux backup tutorial
Submitted by jinlusuh on Sun, 08/16/2009 - 09:18
This is a tutorial on how to make backup on a Linux system. Please read and understand how Linux backup works before attempting to create the real backup job. This tutorial is a step by step guide, so it starts with a simple example and finish with a complete example.
Linux file backup software and backup programs
There are several backup tools in Linux.
- Ubuntu backup using Simple Backup program
- Linux backup using Linux tar command utility
- Linux backup using dd command utility
Ubuntu backup system using Simple Backup program
The Simple Backup program is a gui backup tool. You can install it in Ubuntu Desktop by clicking on the Applications and choose Add/Remove. When the Add/Remove pane opens, type Simple Backup in the Search textbox. You'll see a few backup programs in the result, but what we need is the Simple Backup Suite which includes Simple Backup Config and the Simple Backup Restore.
Here is the description about Simple Backup Suite:
Simple Backup Suite is a set of backend backup daemon and GNOME GUI frontends that provide a simple yet powerful backup solution for common desktop users. Backups can be written to local directory or remote servers using GNOME VFS technology. A fine control is possible regarding what folders and files to backup. Files can be excluded even with a set of regular expressions. Regular backups can be scheduled. This tool has been written with Google sponsorship during Summer of Code 2005 with mentoring help from Ubuntu.
Canonical does not provide updates for Simple Backup Config (and Simple Backup Restore). Some updates may be provided by the Ubuntu community.
Click on the Simple Backup Config and the Simple Backup Restore tickboxes. See the example screenshot below:
A new pane pops up asking you whether you want to apply the changes. Please check that only the Simple Backup Config and the Simple Backup Restore were there. Click Apply button. See the example screenshot below:
Here is the Simple Backup Config and the Simple Backup Restore installation in progress screenshot:
When the installation complete, you'll see a screenshot like the example below:
Now you can start using Simple Backup Config to backup files. Click System and choose Administration. From the list, choose Simple Backup Config to open the backup program. You need to enter your password to do the backup job. Here is the example screenshot of the Simple Backup Config program:
Here is the backup options:
- Use recommended backup settings.
- Use custom backup settings.
- Manual backups only.
You can customize the backup properties, such as:
- Include - Add/Remove directories or files to backup.
- Exclude - Add/Remove directories or files to backup. You can specify the path, file types, regex and max size details.
- Destination - Use default destination (/var/backup), set custom local backup directory or use a remote directory if you want to backup to a network server.
- Time - Set time for a regular manual/automatic backup including a full backup and incremental backup.
- Purging - Set to purge old and incomplete backup.
When you done customizing the backup properties, click Save. Click Backup Now to start backup Ubuntu system.
Backup information and tips:
- Backup can take some times to finish (depends on how many directories and size).
- Testing backup on the disk first before setting backup directly to a cd, dvd or external hard disk.
- Do not put backup on the same hard disk where your Ubuntu resides. Put backup on the second hard disk, cd, dvd or external hard disk.
- Create a full backup at least once a week and daily incremental backup is recommended.
Linux backup using Linux tar command utility
Probably the most popular backup utility in Linux is the tar command. We have discussed about tar command quite detail in Linux tar command - How to archive, compress and extract files in Linux tutorial. You can check the tutorial for more information about tar command syntax, how to make tar archive and compress tar file. Here are some examples on how to do backup using tar command:
To backup only certain files and directories in Linux, we'll use 'tar -cvf' command to archive all the files and directories like in the example below:
The example above creates an archive file named 'selective-backup.tar' which contains tutorials, priority, sony and barcode directories in /var/backup directory. All files have been archived but not compressed.
To backup a complete user's home directory in Linux system, we'll use 'tar -czvf' and automatically compressed the archived file with gunzip using the '-z' option. See the example below:
In the example above, we use absolute path names, so when restoring backup, all files will be restored to their respective directories. We also have a message tar: Removing leading `/' from member names. This statement means a '/' will be removed from all files and directories added to the archive. It will be 'home/luzar/' instead of '/home/luzar/'. The difference is, when restoring an archive file with '/home/luzar/', all the data will be written to the /home directory which eventually will overwrite the existing data while the 'home/luzar/' will be written to wherever it's been extracted to.
If we want to compress file using 'bzip2', using '-j' command instead. The extension for bzip2 compressed destination file is 'file.tar.bz2'.
Here is an example result of an archive file, gunzip compressed and bunzips compressed file. See the different in size:
Linux incremental backup
All backup in the previous examples are full backup. The incremental backup means we only backup data(files and directories) updated after the full backup. This way, we can save both times and hard disk spaces. To make an incremental backup, we have to create a snapshot file during the full backup. Here is a complete command example:
To backup into the external hard disk drive or usb drive, change backup target file to the correct drive mount point. For example, if we want to backup files to the external hard disk drive, mount the external hard disk and use tar command to create the backup:
To backup files into the cd or dvd, see the next section, Backup Linux using dd command.
Backup Linux using dd command utility
Linux dd command is another great backup utility. We have seen files and directories backup examples using tar command. With Linux dd command, you can save those backups in the cd or dvd. More important is that, we can backup the whole hard disk device or the whole system using dd command. Yes, Linux dd command can do that. Here is the meaning of dd as described in info coreutils 'dd invocation':
The Linux dd command's usage format is pretty simple. Here is an example of dd command syntax:
Here is the explanation:
- dd - Convert and copy a file.
- if=/dev/sda - Input (source).
- of=/dev/sdb - Output.
- bs=4096 - Set both input and output block sizes to 4096 bytes.
Yes. That's the Linux dd command syntax you need to backup the first hard disk to the second hard disk.
To backup the gunzip or bzip2 compressed file into the cd or dvd, you need to provide the correct dvd writer drive. Mount the drive if you need to. Here is the example command:
That's it. Good luck!