Cover V14, i04
apr2005.tar

The smbbackup Utility

Sandor Patocs

Although Linux has enjoyed tremendous growth and increased popularity, many organizations still heavily favor the use of Windows. CostWare, the company I work for, provides a cost recovery system for professional organizations such as law firms. It is not uncommon for CostWare to be the only Linux-based application server in a firm.

For larger firms, the task of backing up a Linux system is not a problem. However, for smaller firms with small or non-existent IT departments, this can be a daunting task. The backup software used by smaller organizations often does not provide a backup solution for Linux. In cases like this, CostWare uses a utility called smbbackup to back up the CostWare server to a shared Windows drive. This allows the firm to use its existing Windows-based backup software to archive critical files. One advantage to using this utility is that the Linux system does not need to join the Active Directory domain to back up files to the Windows server.

The smbbackup utility was originally designed to provide a means of backing up Linux systems. It can also be used to back up any other Unix-based system that has a minimal Samba installation in place. smbbackup uses tools that are part of the Samba suite to back up Unix files to a SMB/CIFS (Windows) share. The program uses the smbclient program to perform the actual operations needed to transfer files and directories. Directories and their contents, including sub-directories, are copied to the remote server. Entire directory trees are copied by default. The utility's include/exclude options may be used to include or exclude specific files and directories.

Installation

Installation of the utility is straightforward. Simply download the tar file from http://www.costwareinc.com/freesoftware/. The utility is packaged as a self-extracting executable. Simply run the installer as root and answer a few questions.

The following is a sample installation session:

$./smbbkup.installer

Installation directory [/usr/local/sbin]:
Installng SmbclientParser  ... OK
Installing smbbackup utility  ... OK
Installation complete
Command-Line Options
The smbbackup utility reads options from the command line or from a file using the "directions" option (direction files will be discussed later):

-a /root/authfile, -auth /root/authfile
This option allows you to specify a file from which to read the username, domain name, and password used in the connection. The format of the file is:

username = <value>
password = <value>
domain = <value>
If the domain parameter is missing, then the current workgroup name is used instead. Be sure that the permissions on the file restrict access from unwanted users:

-c, -clean -- New files and directories are copied to the location specified using the --to option. Existing files and directories on the destination server are not removed by default. This means that the "to" location will continue to grow as new files and directories are copied to it. This option causes a remote file or directory to be removed before a new copy is transferred. Directories are removed in their entirety, including sub-directories. Existing files are overwritten when this option is not used.

-d directions, -directions directions -- Instead of specifying options on the command line, all options can be saved in a "directions" file. The options in the file are stored as key/value pairs. The "key" is the name of a command-line option with the leading hyphen(s) optionally removed. The "values" are the same as those used on the command line (see File 1 below):

clean = 1
include = /
exclude = /proc
exclude = /dev
make = 1
auth = /etc/smbbackup/nt_auth
File 1 -- Sample Directions File

-e pattern, -exclude pattern -- Files and directories that match "pattern" are not transferred. The pattern may be a regular expression.

-f back_this_up, -from back_this_up -- The file or directory to be backed up. If a directory is specified, all of its sub-directories are backed up by default. Use the --exclude option to exclude sub-directories. Use a combination of a directory name and an --include pattern to select multiple files for backup.

-i pattern, -include pattern -- Only files and directories that match the given pattern are transferred. The pattern may be a regular expression. "Exclude" directives override "include" directives. You can select multiple files using a wildcard with the --include option and then selectively filter out individual items using --exclude.

-l logfile, -log logfile -- The "logfile" contains a list of all of the files transferred as well as any error messages from the smbclient program.

-p password, -password password -- The "password" for the username used to log in to the remote server. This option is passed to the smbclient program.

-t to_here, -to to_here -- "To_here" is the service name of the remote SMB/CIFS share. The value is in the form //host/share/subfolder where "host" is the name of the remote server and "share" is the share name. This "//host/share" portion of this option is passed to the smbclient program. The subfolder section causes smbackup to backup files to the subfolder indicated, which means that a single share can be used to provide access to multiple backup subfolders.

-u username, -user username -- The username used to log in to the remote server. This option is passed to the smbclient program.

Directions Files

The "directions" option can be used to store backup directions in a file. The options used in the file are the same as those available on the command line. Direction files can be chained together, which is helpful when attempting to put together a complex backup system.

The samples shown in Listings 1-6 are fairly simplistic and reflect how smbbackup can be configured to perform a full and a partial backup for a Linux and Mac OS X system. The name of the full backup file (Listing 1) is passed to the smbackup utility to perform a full backup. The name of the partial backup file (Listing 2) is used when performing a partial backup. Note that the partial backup file relies on the local include files (Listings 4 and 6) to limit the files that are actually backed up. In both cases, user home directories and local application directories are backed up.

The Linux exclude file (Listing 3) excludes items such as /dev and /proc. With these directories excluded, it is safe to use the full backup file (Listing 1) on either the Linux or Mac system.

Also note the date specification in the to directive (see Listings 1 and 2). This means that new backup destination folder names that include the date and time can be generated automatically. The make directive must be used whenever the date is to be embedded into a destination folder's name.

The one-letter variables that begin with a % are expanded using the strftime function. These date conversion specifications are the same as those used by the date command available on most Unix-like systems. See the man page for date or strftime for a complete list of available variables.

Examples

The use of files containing directions is ideal for someone wanting to put together a complete backup system. However, sometimes a quick backup of a local directory or system is all that's needed. Below are a few simple examples that can be run from the command line or from "cron".

To copy all of the files in the Unix directory /home/foobar to the share //server/share:

smbbackup --from /home/foobar --to //server/share --username
Administrator --password password
To copy the files in the Unix directory /home/foobar to the share //server/share, while excluding core files:

smbbackup --from /home/foobar --to //server/share --exclude core
--username Administrator --password password
To copy all files to the share //server/share (this excludes device files, the /proc filesystem, and /tmp):

smbbackup --from / --to //server/share --exclude /dev
--exclude /proc --exclude /tmp --username Administrator --password
password
Restoring Files

Restoring files is accomplished using the smbrestore utility. The command-line options used with smbrestore are virtually the same as those used with smbbackup. The main difference is that the meanings of the from and to options are reversed. The from option is used to refer to a remote Windows share, and to refers to a local directory.

smbrestore accepts the following options:

-a, -auth
-f, -from
-t, -to
-u, -username
-p, -password
-d, -directions
Shortcomings

The smbbackup utility cannot back up special files such as character or block device files, named pipes, and so on. There is no way to make such files on a Windows system. Smbbackup is best suited for backing up regular files and directories that may need to be restored to an already running system. It should not be relied upon for bare-metal restores.

Conclusion

The smbbackup utility provides an easy to use command-line interface for backing up files to an SMB/CIFS share. Through the use of direction files, a systems administrator can configure a fairly complete backup scheme. The utility does not back up device files or other types of special files, so it is not a good tool for a bare-metal recovery. However, when a simple backup of user files and applications is needed, it can be very useful.

Sandor Patocs is a paralegal and a Microsoft Certified Systems Engineer. He has been working as a technical writer, programmer, and administrator of various flavors of Unix for more than 10 years. He works as a senior developer for CostWare, Inc. in Los Angeles. He can be contacted at: sandorpatocs@netscape.net.