This chapter explains how to backup and restore files with the dump command, using Webmin's Filesystem Backup module.
Introduction to backups with dump
There are many ways of backing up a Unix system – you can just copy files to another directory, use the tar command to create an archive file or write to a tape device, or use the dump family of commands. Although copying or using tar is easier, only dump can preserve all file types (such as named pipes and symbolic links) and file information (such as ACLs and attributes). It can do this because it has a more sophisticated knowledge of the underlying filesystem than other backup programs.
Another unique advantage of the dump program is its support for backup levels. If you are regularly backing up the same directory, instead of writing all files to the backup device every time you can choose to save only those files that have changed since the last backup of a lower level. For example, you could do a full backup (level 0) every week, and a much faster partial backup (level 9) each day. The only down side is that if data needed to be restored, the weekly backup and all the daily backups for the week so far would need to be read.
Using dump to make backups has some problems that other backup tools do not. The data that it writes to a file or tape device is not compressed, although this is not a problem with most tape drives as they compress data automatically. Another problem is that it cannot backup files mounted via NFS from another server, as it reads directly from the disk, unlike the tar and cp commands.
The Filesystem Backup module
This module allows you to backup directories on your local filesystems, either on demand or on a fixed schedule. The appropriate command for the filesystem type being backed up is used – for example, xfsdump on xfs filesystems or dump on ext2 or ext3. The module also supports the restoration of backups, either to their original location or to a different path.
When you enter the module from the System category, the main page will display all backups that you currently have configured, as shown in Figure 14-1. Of course, if this is the first time you have used the module there will be done to display.
- Figure 14-1 “The Filesystem Backup module main page”
If Webmin detects that you do not have any of the necessary backup commands installed on your system, an error message will be displayed on the main page instead. All Linux distributions should include a package containing the dump program on their CD or website.
Adding a new backup
If you want to backup a directory, either just occasionally or on a regular schedule, you first need to add a new backup configuration. This specifies a directory to backup, a set of options to use, and the times at which it should be scheduled to run. The steps to follow to create a new configuration are :
- On the main page of the module, enter the path to the directory that you want to backup into the field next to the *Add a new backup of directory* button. When you click the button, Webmin will determine what type of filesystem the directory is in (ext2, ext3 or xfs) and display a backup creation form with options for that filesystem type. Figure 14-2 shows the form for an ext2 or ext3 backup.
- The path you entered will appear in the Directory to backup field. You can still change it if you wish, as long as the new directory that you enter is still on the same filesystem.
- If backing up to a local file, set the Backup to field to the File or tape device option and enter the file that you want the backup written to into the text field next to it. Backing up to a tape drive is similar to writing to a file, but instead of entering a filename into the File or tape device field you must enter the device file for the tape drive. For example, /dev/st0 would be the device file for the first SCSI tape drive on your system. If backing up to another server, you must select the Host option for the Backup to field and enter a hostname, remote username and file or device name on the remote server. The server must have the shell service enabled in its Internet Services module, as explained in chapter 15. An appropriate .rhosts file must also be set up for the target user, to allow the dump command to connect without needing to supply a password.
- If your backup is being written to a local file that you do not want to be larger than a certain size, set the *Split across multiple files?* option to Yes and enter the maximum size in kilobytes into the Tape size field. This can be useful if the backup is going to be later saved to multiple CDs or Zip disks.
- If you are doing multiple backups at different levels as explained in the introduction, change the Dump level field to something other than Full backup. However, if you want each backup to contain all files in the source directory, leave it unchanged at level *0*.
- If you are backing up to a tape, it is a good idea to set the *Tape size* field to the number of kilobytes that can fit on your tape. Otherwise, the dump command may underestimate the amount of data that can be written and fail to complete the backup.
- The chattr command can be used to mark a file to be skipped when making backups, which can be useful if the directory contains huge and useless files that you would rather not save. However, when doing a level 0 backup such files will be included, unless the Always exclude marked files? field is set to Yes.
- If you are familiar with the dump command used on your operating system, the *Extra command-line parameters *field can be used to enter extra options to be passed to the program, such as –A /tmp/archive. Otherwise, leave it blank.
- To have commands run before and after the dump command is executed, fill in the Command to run before backup and *Command to run after backup* fields. These commands will be run as root when the backup is made on scheduled or manually through Webmin. They can be useful for loading and unloading tapes, or copying files into the backup directory before it is saved.
- If you want the backup to be run on a regular schedule, set the Scheduled backup enabled? option to Enabled and select the times and days for it to run from the lists at the bottom of the page. The user interface for date and time selection is exactly the same as the one used by the Scheduled Cron Jobs module.
- To have a status report of the scheduled backup emailed to you, enter your email address into the *Email scheduled output to* field.
- By default, the subject of the back email will be something like Dump of /etc. If you are using this module on multiple systems, you may want to customize the subject line so that the host the email is coming from and the data that has been backed up is more obvious. To do this, de-select the Default option the *Email message subject *field and enter a new subject line into the text field next to it.
- Finally, click the Create button to save the details of the new backup configuration. If there are no errors in the form, the you will be returned to the modules main page. Alternatively, you can begin a backup immediately by clicking *Create and Backup Now*. This will take you to the page showing its progress, as explained in the next section.
- Figure 14-2 “The new backup configuration form”
Apart from ext2 and ext3, the only other filesystem type that has a similar backup command is xfs. Because its xfsdump command has slightly different options, the fields on the new backup form are not quite the same as described above. One important difference is that the Directory to backup must be the mount point of a filesystem, not just any directory within it.
Making a backup
Once you have created a backup configuration that appears on the main page of the module, you can use Webmin to manually execute it at any time. To do this, the steps to follow are :
- From the list of configurations on the module's main page, click on the directory you want to backup. This will take you to a form showing all the details of the backup configuration.
- Click the Backup Now button at the bottom of the page. Webmin will execute the appropriate dump command and display its output as it writes to the backup file or tape device. The output from any commands that are run before or after the backup will be shown as well.
- If all goes well, the message backup complete will be displayed at the bottom of the page. However, if something goes wrong backup failed will be displayed instead – check the output of the dump command to see exactly what the problem was.
One limitation of the Filesystem Backup module is that it cannot create backups that span multiple tapes. Usually the dump command would prompt the user to load a new tape when necessary, but that is not possible when it is being run from Webmin.
Editing or deleting a backup
The backup configurations shown on the module's main page can be edited at any time. To change one, do the following :
- Click on the directory of the backup configuration that you want to change. This will take you to the editing form, which is similar to the creation form shown in Figure 14-2.
- Change any of the options, including the directory to backup, destination or schedule. You cannot change the directory to a path on a different type of filesystem though, as it may have different options or not be supported at all.
- Click the Save button to record your changes, or click *Save and Backup Now* to immediately begin a backup with the new options.
To delete an existing backup configuration, the steps to follow are :
- On the main page, click on the directory of the backup configuration that you want to delete, which will take you to the editing form.
- Click the Delete button at the bottom of the page. The backup configuration will be immediately removed and your will be returned to the main page of the module. The actual backup files created by the configuration will not be touched though.
Restoring a backup
Backups made using Webmin (or by running the dump command manually) can be restored using this module as well. If you have been creating backups of different levels, they must be restored ascending level order starting with the a complete backup (level 0). A backup can be restored to any directory, not just the one that it was originally saved from. However, some file information such as ACLs and attributes will be lost if the restore directory's filesystem does not support them.
To restore a backup, the steps to follow are :
- On the main page of the Filesystem Backup module, select the type of filesystem that the backup was made from using the list next to the Restore backup of filesystem type button. Because there are different programs for restoring different types of filesystems, the restore options will vary depending on the type you choose.
- Click the Restore backup of filesystem type button, which will take you to the restore options page. Figure 14-3 shows the page for restoring an ext2 or ext3 filesystem backup.
- If restoring from a local file, set the Restore from file or device field to the File or tape device option and enter the file that you want the backup read from into the text field next to it. Restoring from a tape drive is similar to reading from a file, but instead of entering a filename into the File or tape device field you must enter the device file for the tape drive - /dev/st0 for example. If restoring from another server, you must select the Host option and enter a hostname, remote username and file or device name on the remote server. As explained in the “Adding a new backup” section, the server must have been configured correctly to allow remote access.
- By default, everything in the backup will be restored. To extract only some files, set the Files to restore option to Listed files and enter paths to the files you want to restore into the field next to it. To restore multiple files, the filenames must be separated by spaces. Because the paths used in the backup are sometimes relative to the mount point of the filesystem that they were originally on, it is often a good idea to use the Only show files in backup? option to see what the correct filenames are.
- In the Restore to directory field, enter the base directory under which you want the restored files to be saved.
- If the original backup spanned multiple files, set the *Backup is split across multiple files?* option to Yes.
- If you just want to view the contents of the backup without extracting any files, set the Only show files in backup? option to Yes.
- If you are familiar with the restore command used on your operating system, the *Extra command-line parameters *field can be used to enter extra options to be passed to the program, such as –A /tmp/archive. Otherwise, leave it blank
- When you are ready to restore, click the Restore Backup Now button. If extracting files for real, a page showing the output of the appropriate restore command will be displayed. If you chose to just view the files in the backup, the page will display a list produced by the restore command instead.
- Figure 14-3 “The backup restoration form”
When restoring a backup from an xfs filesystem, different options are available on the restore form. The Files to restore option does not exist, so all files in the backup will be extracted. However, there is an Overwrite existing files option that can be set to Never to protect existing files, or Unless newer than backup to protect files that have been modified since the backup was made.
One problem with using Webmin to restore is that it cannot cope with backups that span multiple tapes. Normally the restore command would prompt the user to eject the first tape and insert the second, but that is not possible when it is being run by Webmin.
Configuring the Filesystem Backup module
Clicking on the Module Config link in the top-left corner of this module's main page will bring up a form for setting options that control how it behaves. The available settings and their meanings are :
Other operating systems
Many Unix operating systems have similar dump and restore commands to Linux, and several of them are supported by this Webmin module. However, the options available differ slightly, so the backup and restore forms on different systems will not be exactly the same as Linux.
The currently supported systems and their differences are :
- Sun Solaris *On Solaris, ufs filesystems can be backed up and restored using the ufsdump and ufsrestore commands. When creating a backup, the Split across multiple files? and Tape size options are not available – instead, there are *Verify data after backup?* and Eject tape after backup? options whose meanings should be obvious. Solaris also supports the backing up of multiple directories at once, but entering multiple paths separated by spaces into the Directory to backup field. For restoring on Solaris, the options are essentially the same as on Linux.
- FreeBSD and Apple MacOS X *Both these operating systems have almost identical dump commands and available options in Webmin, due to the BSD ancestry of MacOS X. When making a backup, the *Split across multiple files?* and Dump label fields are not available, but Tape size is. The only filesystem type that can be backed up is ufs. Unfortunately on MacOS X, almost all filesystems are in Apple's native hfs format. When restoring, the only difference is an additional Just test backup? option which when set causes the restore command to do everything except write to disk.
- SGI Irix *On Irix, the only filesystem type that can be backed up with Webmin is xfs, even though there is a dump command for older efs filesystems. As with the xfs filesystem on Linux, only entire filesystems can be backed up, not arbitrary directories. The Tape size option is not available, but instead you can limit the size of files to include with the Maximum file size to include option, and turn off the backing up of attributes with the *Include file attributes?* option. When restoring a backup on Irix, there is no option to specify which files to extract – instead, everything in the backup will be restored. However, there is an *Overwrite existing files?* option to protect existing files or existing files that are newer than the backup from being overwritten.
Due to the low-level nature of backups made using the dump family of commands, a backup created on one operating system will not be restorable on any other.