Simple usage
Even the world's best backup service is useless if it's not used properly. Fortunately, there's only two steps to proper backups:
- Making backups
- Testing / restoring backups
Remember that thanks to deduplication, only unique data will be uploaded. It's better to create "too many" backups rather than "not enough"!
Assumptions
This page assumes that:
- You installed Tarsnap to /usr/local/bin/.
- You are using a configuration file that has keyfile and cachedir set.
- You have a /root directory.
-
You would like to use Tarsnap as the root user. If
necessary, become root by running:
su
If any of those assumptions are incorrect, no problem! Simply adjust the directory names (below), or add --keyfile and --cachedir, as appropriate.
Step 1: Making backups
First, create a backup script; this may be run manually, or scheduled to run automatically.
Step 1A: Backup script
-
Create a /root/tarsnap-backup.sh script containing:
#!/bin/sh # Set up archive name computer=$(uname -n) now=$(date +%Y-%m-%d_%H-%M-%S) name=${computer}-${now} # Create an archive /usr/local/bin/tarsnap -c \ -f "${name}" \ /MY/DATADIRPlease note:-
We recommend using the full path, as this avoids
potential problems with
$PATHand crontab.
Note: the above script assumes that you installed tarsnap into /usr/local/bin, but many package managers on Linux install it to /usr/bin instead. - Replace /MY/DATADIR as appropriate.
-
The
-fcommand defines the "archive name" in which your data is stored on the Tarsnap servers.-
The command $(uname -n) automatically turns into
your computer's
$HOSTNAME. - Optionally, change the format of the timestamp.
-
The command $(uname -n) automatically turns into
your computer's
-
We recommend using the full path, as this avoids
potential problems with
-
Make the script executable, then run it whenever you
want:
chmod u+x /root/tarsnap-backup.sh
/root/tarsnap-backup.sh
- Check that you can restore these backups with Step 2: Testing / restoring backups.
Step 1B: Automatic backups (optional)
-
Add this to your
crontab:
14 5 * * * /root/tarsnap-backup.sh
- Wait a day for the script to run automatically.
- Check that you can restore these backups with Step 2: Testing / restoring backups.
Step 2: Testing / restoring backups
Second, check that the previous backup(s) worked.
-
See a list of archives:
tarsnap --list-archives | sort
-
Restore one of those archives:
tarsnap -x -f mycomputer-2015-08-09_19-37-20
- Check that the files and directories are what you expect.
More advanced usage
There are many other options available with
tarsnap. We recommend reading the
tips,
then the
general usage
documentation or
read the
man pages.
