Backups
5.1
A backup is a copy of your files somewhere else: a USB disk, another
machine, a server. A disk dies, a laptop gets lost, a command deletes
the wrong directory; with a recent copy you lose an hour, not years.
This page shows what to save on SliTaz and how, with the tools in the
packages, from a plain tar to versioned and encrypted backups.
What to save
- Your home:
/home/tux(or your user), with its hidden files: documents, mail, browser profile, settings of the desktop. - The system settings you changed, in
/etc:network.conf,wpa/wpa.conf(Wi-Fi keys),rcS.conf,init.d/local.sh,fstab,hostname,keymap.conf,locale.conf, and the configuration of your servers. - The list of installed packages, to install the same set again on a new system.
- Your scheduled tasks:
/var/spool/cron/crontabs.
The rest of the system comes back with a fresh install from the ISO.
The list of packages
spk marks the packages it pulled in as dependencies (a .auto file in
their directory); the others are the ones that were asked for. Save
their names:
$ for p in /var/lib/tazpkg/installed/*; do [ -e $p/.auto ] || basename $p; done > my-packages.list
On the new system, install them all at once; the ones already there are skipped:
# spk-add $(cat my-packages.list)
spk-ls shows the installed packages with their versions.
An archive with tar
tar is in every SliTaz, Base included. A compressed archive of your
home, without the caches, on a USB disk mounted on /media/BACKUP:
$ tar -czf /media/BACKUP/home-$(date +%Y%m%d).tar.gz -C /home --exclude .cache tux
-z is gzip, always there. For smaller archives, use xz (-J) after
spk-add xz; it is slower:
$ tar -cJf /media/BACKUP/home-$(date +%Y%m%d).tar.xz -C /home --exclude .cache tux
The settings, as root (the archive holds Wi-Fi keys and passwords: keep it in a safe place):
# tar -czf /media/BACKUP/etc-$(date +%Y%m%d).tar.gz -C / etc var/spool/cron
List an archive with tar -tzf (or -tJf); restore it with -x:
$ tar -xzf /media/BACKUP/home-20261125.tar.gz -C /home
Do not restore all of /etc onto a new install: fstab and the boot
settings name the partitions of the old disk. Extract the archive in
a directory and copy back the files you need.
A copy with rsync
rsync keeps a copy of a directory up to date: the first run copies
everything, the next ones only what changed. Install it with
spk-add rsync.
$ rsync -aH --delete /home/tux/ /media/BACKUP/tux/
The slash at the end of each path matters: it copies the contents of
tux/ into tux/. --delete removes from the copy what you deleted
from your home; try first with -n (dry run) to see what would
change. -A -X also keep the ACLs and extended attributes, on a Linux
file system.
To another machine over SSH, with rsync installed on both sides (the
dropbear package provides the ssh command):
$ rsync -aH --delete /home/tux/ tux@192.168.1.10:backup/tux/
The copy on a FAT or exFAT disk loses owners and permissions: format the backup disk in ext4 if you can.
Versioned and encrypted: restic
A copy holds only the last state: if a file was damaged a week ago, the copy is damaged too. restic keeps snapshots, stores each piece of data once, and encrypts everything with a password. It is packaged for i486 and x86_64:
# spk-add restic
Create a repository on the backup disk (restic asks for its password: without it the backups cannot be read, by anybody):
$ restic init -r /media/BACKUP/restic
Back up your home, list the snapshots, and keep the last 7:
$ restic -r /media/BACKUP/restic backup /home/tux --exclude /home/tux/.cache
$ restic -r /media/BACKUP/restic snapshots
$ restic -r /media/BACKUP/restic forget --keep-last 7 --prune
Restore the last snapshot into a directory, then copy back what you need:
$ restic -r /media/BACKUP/restic restore latest --target /tmp/restore
The files land under /tmp/restore/home/tux. restic check verifies
the repository. restic also writes to an SFTP server
(-r sftp:user@host:/path) and to many cloud storages.
Other packaged tools: rsnapshot (snapshots made of rsync and hard links), rdiff-backup, dar, duplicity.
Every day, by itself
BusyBox crond runs commands on a schedule. Put your backup in a script,
for example /home/tux/bin/backup.sh, make it executable, then add it
to your table with crontab -e:
0 20 * * * /home/tux/bin/backup.sh
crond must run: see Scheduled tasks in the Handbook. A backup that needs a USB disk only works when the disk is plugged in; a script can check it first:
mountpoint -q /media/BACKUP || exit 0
What SliTaz keeps by itself
These are not backups of your files, but they help after a bad upgrade:
- before each upgrade,
spk-upkeeps the packages it replaces in/var/cache/spk/previous; - reprise keeps snapshots of
/etc, the boot loader settings and the package list in/var/lib/reprise/snapshots, and saves every file it repairs;reprise --undoputs them back. See Repair a broken system.
They live on the same disk as the system: if the disk dies, they go with it.
Tips
- Keep one copy away from the machine: a disk at another place, or another computer. A backup next to the laptop is stolen with it.
- Try a restore once in a while: a backup you never read back may be empty.
- An encrypted backup disk: see Encrypted disk.
- On a live system with a
home=partition, your files are on that partition: back it up like any home.
Troubleshooting
tar: "short read" or "invalid tar magic" when reading an archive:
the compression option does not match the file. Use -z for .gz,
-J for .xz, or check the type with hexdump -C file | head -1.
BusyBox tar cannot write .lzma archives: use -z or -J.
rsync stops at once with "rsync: not found" or "connection unexpectedly closed": rsync is missing on the remote machine: install it there too.
restic: "Fatal: repository does not exist": the disk is not
mounted, or the path after -r is wrong.