Backups SliTaz 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

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:

They live on the same disk as the system: if the disk dies, they go with it.

Tips

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.