Skip to content

patrick-brigel/restic-mkstage4

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

restic-mkstage4

This is a set of Bash scripts which create, copy and restore “stage 4” backups (i.e. full system snapshots) of a Gentoo Linux system using restic as the backup backend.

It is a reimplementation of the original TheChymera/mkstage4, which was itself inspired by an earlier mkstage4 script by Greg Fitzgerald (unmaintained as of 2012), which itself was a revamped edition of the original mkstage4 by Reto Glauser (unmaintained as of 2009). All credit for the original concept, exclude logic and CLI design goes to those authors; this fork only swaps the tar/rsync backend for restic.

Installation

The scripts can be run directly from their containing folder (and thus, are installed simply by downloading or cloning the repo - and adding run permissions):

git clone https://github.com/patrick-brigel/restic-mkstage4.git ~/restic-mkstage4
cd ~/restic-mkstage4
chmod +x restic-cpstage4.sh restic-exstage4.sh restic-mkstage4.sh

The restic repository must already be initialized (restic init) before first use.

Usage

Snapshots created by restic-mkstage4.sh are tagged stage4 by default; restic-cpstage4.sh and restic-exstage4.sh filter on that same tag by default.

Examples

Back up your current system (mounted at /) to a local restic repo:

./restic-mkstage4.sh -s -r /mnt/backup/restic-repo

Back up a system located at a custom mount point, excluding /home:

./restic-mkstage4.sh -t /mnt/gentoo -H -r /mnt/backup/restic-repo

Copy the latest stage4 snapshot from one restic repo to another:

./restic-cpstage4.sh -f /mnt/backup/restic-repo -r /mnt/backup2/restic-repo

Restore the latest stage4 snapshot from a restic repo into a target directory:

./restic-exstage4.sh -r /mnt/backup/restic-repo -t /mnt/gentoo

Command line arguments

Usage:
	restic-mkstage4.sh [-b -c -H -l -q] [-r <restic-repo>] [-s || -t <target-mountpoint>] [-e <additional excludes dir*>] [-i <additional include target>] [-- custom-restic-options]
	-b: excludes boot directory.
	-c: excludes some confidential files (currently only .bash_history and connman network lists).
	-H: excludes the home directory.
	-l: excludes lost+found directory.
	-q: activates quiet mode (no confirmation).
	-r: restic repository (overrides the RESTIC_REPOSITORY env var).
	-s: back up the current system.
	-t: back up the system located at the <target-mountpoint>.
	-e: an additional excludes directory (one dir one -e, do not use it with *).
	-i: an additional target to include. This has higher precedence than -e, -t, and -s.
	-h: display this help message.
Usage:
	restic-cpstage4.sh [-q] [-T <tag>] -f <source-restic-repo> -r <destination-restic-repo> [snapshot-id ...] [-- custom-restic-options]
	-f: source restic repository to copy snapshots from.
	-r: destination restic repository to copy snapshots to (overrides the RESTIC_REPOSITORY env var).
	-T: only copy snapshots with the given tag (default: stage4, pass empty string to disable).
	-q: activates quiet mode (no confirmation).
	-h: display this help message.
	If no snapshot-id is given, "latest" is used.
Usage:
	restic-exstage4.sh [-q] [-T <tag>] [-r <restic-repo>] -t <target-dir> [snapshot-id] [-- custom-restic-options]
	-r: restic repository (overrides the RESTIC_REPOSITORY env var).
	-t: target directory to restore into.
	-T: restrict to snapshots with the given tag (default: stage4, pass empty string to disable).
	-q: activates quiet mode (no confirmation).
	-h: display this help message.
	If no snapshot-id is given, "latest" is used.

Passing extra arguments / env vars to restic

Anything after -- is passed through verbatim to the underlying restic call, so any restic flag (additional tags, compression, parent snapshots, host name, etc.) is supported. See the restic docs for the full list of flags and supported backends:

./restic-mkstage4.sh -s -r /mnt/backup/restic-repo -- --tag stage4 --host tux --compression max

Any restic environment variable also works. The repository can be supplied via RESTIC_REPOSITORY instead of -r, and remote backends (S3, B2, Azure, REST server, SFTP, …) are configured via their usual restic env vars.

For the repository password, prefer RESTIC_PASSWORD_COMMAND (fetched from a secret store at runtime) or a chmod 0600 RESTIC_PASSWORD_FILE kept outside the backup set (e.g. /etc/restic/password).

RESTIC_REPOSITORY="s3:s3.amazonaws.com/my-bucket/stage4" \
	RESTIC_PASSWORD_COMMAND="pass show restic/stage4" \
	AWS_ACCESS_KEY_ID="..." \
	AWS_SECRET_ACCESS_KEY="..." \
	./restic-mkstage4.sh -s

Dependencies

restic must be available in $PATH.

License

See LICENSE.

About

Bash scripts to create, copy, and restore Gentoo stage 4 (full system) backups using restic

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages