This is a simple wrapper around tar to manage a number of backups for sources
into a destination directory. The destination directory will automatically be
created and this wrapper will create files which names contain the time and date
of the backup. The resulting tar files will automatically be compressed using
gzip
compression for maximal compatibility across architectures. The utility
is able to execute a command once the backup operation has finalised. One new
tar file is created every time tar.sh
is run, meaning that it should probably
be scheduled on a regular basis from the outside, e.g. with cron
.
When the utility's main name is untar
instead (or when the option --untar
is
given), it will look for the latest compressed tar file and unpack into the
destination directory instead.
Packing and unpacking operations are by default using checksums to protect against data transfer errors.
tar.sh
takes a number of single or double-dashed options, followed by the
command to execute once the tar operation has been performed. It is preferable
to separate the list of options from the command using a single double-dash, to
mark the definitive end of the options.
The following options are recognised.
The value of this option should be the path to a destination directory that will contain the date-based tar files that are created. The directory will be created if it does not exist.
The value of this option can be the path to a source directory, the default is
an empty value, meaning the current directory. Whenever this option is not
empty, it will be passed to tar
as the directory to change to before
performing the tar operation. In practice, this is a relay to the -C
option,
present in most tar implementations, including the one from busybox.
Prefix string to add at the beginning of each tar file name that will be
created. This defaults to an empty string. The remaining of the name will be
formed of a timestamp in the following format: %Y%m%d%H%M%S
and of the
compressed ending extension, i.e. .tgz
.
The value of this option is a (list of) file(s) or directory/ies to add to the compressed tar file. It cannot be empty, otherwise the utility will end with an error.
Act in reverse! When this option is given, it will look for the latest
compressed tar file starting with the prefix from --prefix
in the source
directory specified by --source
and extract the content of this file, if it
exists, to the destination directory. The value of --files
is understood in
order to only extract some of the files/directories, if necessary.
This is to force the tar and compress "regular" behaviour, as opposed to
--untar
.
The content of this option should point to an executable to run for the
generation of checksums. By default, this is sha256sum
. The name of this
program (sans the word sum
) will be used as the extension for the file that
will contain the checksum and this file will be stored in the same directory.
When unpacking, the latest file that have a proper checksum will be used,
starting from the youngest one (but see --youngest
). Files without checksums
or with checksums mismatched will be ignored.
When this flag is turned on, the behaviour of the unpacking operations with non-matching checksums will change slightly. Instead of parsing back in time until it finds a proper tar/compressed file, i.e. with a proper checksum, the program will only try with the youngest files of all.
When this file is turned on, only a version of a tar file will be kept. In other words, once a new tar file has been created, if it identical to the previous one that was created, it will automatically be removed, together with its checksum.
This utility is tuned for maximal compatibility. It only requires a basic POSIX
shell and uses tar options that are found in most implementation, including the
one from busybox. As a result, tar.sh
can easily be used from containers or
in embedded systems.