smbtar
Backup/restore SMB shares to/from tar archives
SYNOPSIS
smbtar //server/share {-c | -x | -t} [smbtar_options] [tar_options]
smbtar -s //server/share {-c | -x | -t} [smbtar_options] [tar_options]
PARAMETERS
-c
Create a new archive (backup mode). Files from the SMB share are written to the tar archive.
-x
Extract files from an archive (restore mode). Files are read from the tar archive and written to the local filesystem.
-t
List the contents of an archive. Displays the names of files in the tar archive.
-s //server/share
Specify the SMB share to connect to for backup or restore. This can also be provided as the first argument without the '-s' flag.
-u
Specify the username for authenticating to the SMB share.
-p
Specify the password for the SMB username. If omitted, smbtar will prompt for it securely.
-N
Perform an incremental backup. Only files newer than the timestamp stored in
-a
Used with -N, indicates an archive (full) backup. Resets the timestamp in the file specified by -N to the current time, ensuring a full backup next time.
-i
Force incremental backup, even if the state file (-N) does not exist or is empty. A full backup will be performed if no state file is found.
-E
Exclude files listed in
-r
Specify a remote directory on the SMB share to start the backup or restore operation from. Defaults to the root of the specified share.
-D
Change to
-T
Specify the full path to the tar binary to use. Defaults to 'tar', but can be useful for specifying 'gtar' or other specific versions.
-v
Enable verbose output, displaying more details about the operation, including files being processed.
-d
Set the debug level for smbclient operations (0-10). Higher numbers provide more detailed output for troubleshooting.
-l
Specify a file to write debug messages to, instead of standard error.
DESCRIPTION
smbtar is a shell script that acts as a wrapper around the smbclient and tar utilities, designed to facilitate backups of files and directories from SMB/CIFS network shares. It provides a convenient way to automate the process of connecting to a remote Windows or Samba share, listing its contents, and then piping those contents directly to tar for archiving. This allows users to create archives (e.g., to a local disk, tape drive, or another remote location via a pipe) without first mounting the remote share locally.
It handles authentication against the SMB share and supports various tar options for compression, verbosity, and specifying archive destinations. smbtar is particularly useful in mixed environments where Linux systems need to back up data residing on Windows servers or other Samba-enabled network-attached storage, offering a scriptable and non-interactive backup solution.
CAVEATS
smbtar is a shell script, meaning its performance can be limited compared to compiled binaries, especially with very large numbers of files due to overheads in file listing via smbclient. It relies heavily on the correct functioning and presence of both smbclient and tar utilities on the local system.
Authentication challenges, such as special characters in passwords or complex domain authentication schemes, can sometimes be problematic. Permissions and extended attributes on files transferred via SMB may not be fully preserved or restored accurately, as SMB's capabilities differ from local Unix file systems. For modern backup strategies, direct rsync over SMB (if supported) or mounting shares with mount.cifs and then using tar or rsync directly might offer more flexibility or performance.
HOW IT WORKS INTERNALLY
smbtar operates by piping the output of an smbclient command directly into the standard input of the tar command. For a backup operation (-c), smbclient is instructed to list and get files from the remote share, and this data stream is consumed by tar to create an archive. For a restore operation (-x), tar extracts files from an archive (typically from standard input or a specified file), and these files are then sent via smbclient to the remote share using the 'put' command.
INTEGRATION WITH TAR OPTIONS
Beyond its own specific options, smbtar seamlessly passes almost all other command-line arguments directly to the underlying tar command. This allows users to leverage tar's extensive features, such as compression (e.g., -z for gzip, -j for bzip2, -J for xz), specifying an archive file (e.g., -f /path/to/archive.tar.gz), and verbosity settings, making smbtar highly flexible for various backup requirements. For instance, smbtar //server/share -c -z -f /backup/share.tar.gz would create a compressed gzip tar archive.
HISTORY
smbtar originated as part of the Samba suite, a collection of free software implementations of SMB/CIFS protocols. Its development dates back to the early days of Samba, providing a crucial utility for performing network backups from Unix/Linux systems to and from Windows and other SMB/CIFS file servers. In an era when direct mounting of SMB shares was less common or robust, smbtar offered a reliable method to stream data.
While newer tools and methods (like direct file copying with rsync over mounted CIFS shares) have emerged, smbtar remains a functional and often relied-upon script for straightforward network backups in heterogeneous environments, maintaining its place within the Samba distribution for compatibility and ease of use in specific scenarios.
SEE ALSO
smbclient(1), tar(1), rsync(1), mount.cifs(8), samba(7)