restic

restic is a backup program which allows saving multiple revisions of files and directories in an encrypted repository stored on different backends.

Usage

Usage: restic [command] [options]

Global Options

OptionEnvironmentDescription
--cacert file$RESTIC_CACERTfile to load root certificates from (default: use system certificates or $RESTIC_CACERT)
--cache-dir directoryset the cache directory. (default: use system default cache directory)
--cleanup-cacheauto remove old cache directories
--compression mode$RESTIC_COMPRESSIONcompression mode (only available for repository format version 2), one of (auto/off/max) (default: $RESTIC_COMPRESSION) (default auto)
-h, --helphelp for restic
--http-user-agent stringset a http user agent for outgoing http requests
--insecure-no-passworduse an empty password for the repository, must be passed to every restic command (insecure)
--insecure-tlsskip TLS certificate verification when connecting to the repository (insecure)
--jsonset output mode to JSON for commands that support it
--key-hint key$RESTIC_KEY_HINTkey ID of key to try decrypting first (default: $RESTIC_KEY_HINT)
--limit-download ratelimits downloads to a maximum rate in KiB/s. (default: unlimited)
--limit-upload ratelimits uploads to a maximum rate in KiB/s. (default: unlimited)
--no-cachedo not use a local cache
--no-extra-verifyskip additional verification of data before upload (see documentation)
--no-lockdo not lock the repository, this allows some operations on read-only repositories
-o, --option key=valueset extended option (key=value, can be specified multiple times)
--pack-size size$RESTIC_PACK_SIZEset target pack size in MiB, created pack files may be larger (default: $RESTIC_PACK_SIZE)
--password-command command$RESTIC_PASSWORD_COMMANDshell command to obtain the repository password from (default: $RESTIC_PASSWORD_COMMAND)
-p, --password-file file$RESTIC_PASSWORD_FILEfile to read the repository password from (default: $RESTIC_PASSWORD_FILE)
-q, --quietdo not output comprehensive progress report
-r, --repo repository$RESTIC_REPOSITORYrepository to backup to or restore from (default: $RESTIC_REPOSITORY)
--repository-file file$RESTIC_REPOSITORY_FILEfile to read the repository location from (default: $RESTIC_REPOSITORY_FILE)
--retry-lock durationretry to lock the repository if it is already locked, takes a value like 5m or 2h (default: no retries)
--stuck-request-timeout durationduration after which to retry stuck requests (default 5m0s)
--tls-client-cert file$RESTIC_TLS_CLIENT_CERTpath to a file containing PEM encoded TLS client certificate and private key (default: $RESTIC_TLS_CLIENT_CERT)
-v, --verbosebe verbose (specify multiple times or a level using —verbose=n, max level/times is 2)

backup

The “backup” command creates a new snapshot and saves the files and directories given as the arguments.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was a fatal error (no snapshot created).
  • Exit status is 3 if some source data could not be read (incomplete snapshot created).
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic backup [flags] [FILE/DIR] ...

OptionEnvironmentDescription
-n, --dry-rundo not upload or write any data, just show what would be done
-e, --exclude patternexclude a pattern (can be specified multiple times)
--exclude-cachesexcludes cache directories that are marked with a CACHEDIR.TAG file. See https://bford.info/cachedir/ for the Cache Directory Tagging Standard
--exclude-file fileread exclude patterns from a file (can be specified multiple times)
--exclude-if-present filename[:header]takes filename[:header], exclude contents of directories containing filename (except filename itself) if header of that file is as provided (can be specified multiple times)
--exclude-larger-than sizemax size of the files to be backed up (allowed suffixes: k/K, m/M, g/G, t/T)
--files-from fileread the files to backup from file (can be combined with file args; can be specified multiple times)
--files-from-raw fileread the files to backup from file (can be combined with file args; can be specified multiple times)
--files-from-verbatim fileread the files to backup from file (can be combined with file args; can be specified multiple times)
-f, --forceforce re-reading the source files/directories (overrides the “parent” flag)
-g, --group-by groupgroup snapshots by host, paths and/or tags, separated by comma (disable grouping with ”) (default host,paths)
-H, --host hostname$RESTIC_HOSTset the hostname for the snapshot manually. To prevent an expensive rescan use the “parent” flag
--iexclude patternsame as —exclude pattern but ignores the casing of filenames
--iexclude-file filesame as —exclude-file but ignores casing of filenames in patterns
--ignore-ctimeignore ctime changes when checking for modified files
--ignore-inodeignore inode number and ctime changes when checking for modified files
--no-scando not run scanner to estimate size of backup
-x, --one-file-systemexclude other file systems, don’t cross filesystem boundaries and subvolumes
--parent snapshotuse this parent snapshot (default: latest snapshot in the group determined by —group-by and not newer than the timestamp determined by —time)
--read-concurrency n$RESTIC_READ_CONCURRENCYread n files concurrently (default: $RESTIC_READ_CONCURRENCY or 2)
--skip-if-unchangedskip snapshot creation if identical to parent snapshot
--stdinread backup from stdin
--stdin-filename filenamefilename to use when reading from stdin (default “stdin”)
--stdin-from-commandinterpret arguments as command to execute and store its stdout
--tag tagsadd tags for the new snapshot in the format tag[,tag,...] (can be specified multiple times) (default [])
--time timetime of the backup (ex. ‘2012-11-01 22:08:41’) (default: now)
--with-atimestore the atime for all files and directories

cache

The “cache” command allows listing and cleaning local cache directories.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.

Usage: restic cache [flags]

OptionEnvironmentDescription
--cleanupremove old cache directories
--max-age daysmax age in days for cache directories to be considered old (default 30)
--no-sizedo not output the size of the cache directories

cat

The “cat” command is used to print internal objects to stdout.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic cat [flags] [masterkey|config|pack ID|blob ID|snapshot ID|index ID|key ID|lock ID|tree snapshot:subfolder]

check

The “check” command tests the repository for errors and reports any errors it finds. It can also be used to read all data and therefore simulate a restore.

By default, the “check” command will always load all data directly from the repository and not use a local cache.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic check [flags]

OptionDescription
--read-dataread all data blobs
--read-data-subset subsetread a subset of data packs, specified as ‘n/t’ for specific part, or either ‘x%’ or ‘x.y%’ or a size in bytes with suffixes k/K, m/M, g/G, t/T for a random subset
--with-cacheuse existing cache, only read uncached data from repository

copy

The “copy” command copies one or more snapshots from one repository to another.

NOTE: This process will have to both download (read) and upload (write) the entire snapshot(s) due to the different encryption keys used in the source and destination repositories. This may incur higher bandwidth usage and costs than expected during normal backup runs.

NOTE: The copying process does not re-chunk files, which may break deduplication between the files copied and files already stored in the destination repository. This means that copied files, which existed in both the source and destination repository, may occupy up to twice their space in the destination repository. This can be mitigated by the --copy-chunker-params option when initializing a new destination repository using the “init” command.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic copy [flags] [snapshotID ...]

OptionEnvironmentDescription
--from-insecure-no-passworduse an empty password for the source repository (insecure)
--from-key-hint string$RESTIC_FROM_KEY_HINTkey ID of key to try decrypting the source repository first (default: $RESTIC_FROM_KEY_HINT)
--from-password-command command$RESTIC_FROM_PASSWORD_COMMANDshell command to obtain the source repository password from (default: $RESTIC_FROM_PASSWORD_COMMAND)
--from-password-file file$RESTIC_FROM_PASSWORD_FILEfile to read the source repository password from (default: $RESTIC_FROM_PASSWORD_FILE)
--from-repo repository$RESTIC_FROM_REPOSITORYsource repository to copy snapshots from (default: $RESTIC_FROM_REPOSITORY)
--from-repository-file file$RESTIC_FROM_REPOSITORY_FILEfile from which to read the source repository location to copy snapshots from (default: $RESTIC_FROM_REPOSITORY_FILE)
-H, --host host$RESTIC_HOSTonly consider snapshots for this host (can be specified multiple times) (default: $RESTIC_HOST)
--path pathonly consider snapshots including this (absolute) path (can be specified multiple times, snapshots must include all specified paths)
--tag tag[,tag,...]only consider snapshots including tag[,tag,...] (can be specified multiple times) (default [])

diff

The “diff” command shows differences from the first to the second snapshot. The first characters in each line display what has happened to a particular file or directory:

  • + The item was added
  • - The item was removed
  • U The metadata (access mode, timestamps, …) for the item was updated
  • M The file’s content was modified
  • T The type was changed, e.g. a file was made a symlink
  • ? Bitrot detected: The file’s content has changed but all metadata is the same

Metadata comparison will likely not work if a backup was created using the --ignore-inode or --ignore-ctime option.

To only compare files in specific subfolders, you can use the snapshotID:subfolder syntax, where subfolder is a path within the snapshot.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic diff [--metadata] snapshotID snapshotID

dump

The “dump” command extracts files from a snapshot from the repository. If a single file is selected, it prints its contents to stdout. Folders are output as a tar (default) or zip file containing the contents of the specified folder. Pass ”/” as file name to dump the whole snapshot as an archive file.

The special snapshotID “latest” can be used to use the latest snapshot in the repository.

To include the folder content at the root of the archive, you can use the snapshotID:subfolder syntax, where subfolder is a path within the snapshot.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic dump [flags] snapshotID file

OptionEnvironmentDescription
-a, --archive formatset archive format as “tar” or “zip” (default “tar”)
-H, --host host$RESTIC_HOSTonly consider snapshots for this host, when snapshot ID “latest” is given (can be specified multiple times) (default: $RESTIC_HOST)
--path pathonly consider snapshots including this (absolute) path, when snapshot ID “latest” is given (can be specified multiple times, snapshots must include all specified paths)
--tag tag[,tag,...]only consider snapshots including tag[,tag,...], when snapshot ID “latest” is given (can be specified multiple times) (default [])
-t, --target pathwrite the output to target path

find

The “find” command searches for files or directories in snapshots stored in the repo. It can also be used to search for restic blobs or trees for troubleshooting. The default sort option for the snapshots is youngest to oldest. To sort the output from oldest to youngest specify --reverse.

Usage: restic find [flags] PATTERN...

Examples:

restic find config.json
restic find --json "*.yml" "*.json"
restic find --json --blob 420f620f b46ebe8a ddd38656
restic find --show-pack-id --blob 420f620f
restic find --tree 577c2bc9 f81f2e22 a62827a9
restic find --pack 025c1d06

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.
OptionEnvironmentDescription
--blobpattern is a blob-ID
-H, --host host$RESTIC_HOSTonly consider snapshots for this host (can be specified multiple times) (default: $RESTIC_HOST)
--human-readableprint sizes in human readable format
-i, --ignore-caseignore case for pattern
-l, --longuse a long listing format showing size and mode
-N, --newest stringnewest modification date/time
-O, --oldest stringoldest modification date/time
--packpattern is a pack-ID
--path pathonly consider snapshots including this (absolute) path (can be specified multiple times, snapshots must include all specified paths)
-R, --reversereverse sort order oldest to newest
--show-pack-iddisplay the pack-ID the blobs belong to (with —blob or —tree)
-s, --snapshot idsnapshot id to search in (can be given multiple times)
--tag tag[,tag,...]only consider snapshots including tag[,tag,...] (can be specified multiple times) (default [])
--treepattern is a tree-ID

forget

The “forget” command removes snapshots according to a policy. All snapshots are first divided into groups according to --group-by, and after that the policy specified by the --keep-* options is applied to each group individually. If there are not enough snapshots to keep one for each duration related --keep-{within-,}* option, the oldest snapshot in the group is kept additionally.

Please note that this command really only deletes the snapshot object in the repository, which is a reference to data stored there. In order to remove the unreferenced data after “forget” was run successfully, see the “prune” command.

Please also read the documentation for “forget” to learn about some important security considerations.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic forget [flags] [snapshot ID] [...]

OptionEnvironmentDescription
-l, --keep-last nkeep the last n snapshots (use ‘unlimited’ to keep all snapshots)
-H, --keep-hourly nkeep the last n hourly snapshots (use ‘unlimited’ to keep all hourly snapshots)
-d, --keep-daily nkeep the last n daily snapshots (use ‘unlimited’ to keep all daily snapshots)
-w, --keep-weekly nkeep the last n weekly snapshots (use ‘unlimited’ to keep all weekly snapshots)
-m, --keep-monthly nkeep the last n monthly snapshots (use ‘unlimited’ to keep all monthly snapshots)
-y, --keep-yearly nkeep the last n yearly snapshots (use ‘unlimited’ to keep all yearly snapshots)
--keep-within durationkeep snapshots that are newer than duration (e.g., 1y5m7d2h) relative to the latest snapshot
--keep-within-hourly durationkeep hourly snapshots newer than duration (e.g., 1y5m7d2h) relative to the latest snapshot
--keep-within-daily durationkeep daily snapshots newer than duration (e.g., 1y5m7d2h) relative to the latest snapshot
--keep-within-weekly durationkeep weekly snapshots newer than duration (e.g., 1y5m7d2h) relative to the latest snapshot
--keep-within-monthly durationkeep monthly snapshots newer than duration (e.g., 1y5m7d2h) relative to the latest snapshot
--keep-within-yearly durationkeep yearly snapshots newer than duration (e.g., 1y5m7d2h) relative to the latest snapshot
--keep-tag taglistkeep snapshots with this taglist (can be specified multiple times) (default [])
--unsafe-allow-remove-allallow deleting all snapshots of a snapshot group
--host host$RESTIC_HOSTonly consider snapshots for this host (can be specified multiple times) (default: $RESTIC_HOST)
--tag tag[,tag,...]only consider snapshots including tag[,tag,...] (can be specified multiple times) (default [])
--path pathonly consider snapshots including this (absolute) path (can be specified multiple times, snapshots must include all specified paths)
-c, --compactuse compact output format
-g, --group-by groupgroup snapshots by host, paths and/or tags, separated by comma (disable grouping with ”) (default host,paths)
-n, --dry-rundo not delete anything, just print what would be done
--pruneautomatically run the ‘prune’ command if snapshots have been removed
--max-unused limittolerate given limit of unused data (absolute bytes with suffixes k/K, m/M, g/G, t/T, %, or ‘unlimited’) (default “5%“)
--max-repack-size sizestop after repacking this much data in total (allowed suffixes: k/K, m/M, g/G, t/T)
--repack-cacheable-onlyonly repack packs which are cacheable
--repack-smallrepack pack files below 80% of target pack size
--repack-uncompressedrepack all uncompressed data
--repack-smaller-than below-limitpack below-limit packfiles (allowed suffixes: k/K, m/M)

init

The “init” command initializes a new repository.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.

Usage: restic init [flags]

OptionEnvironmentDescription
--copy-chunker-paramsCopy chunker parameters from the secondary repository (useful with the copy command)
--from-insecure-no-passwordUse an empty password for the source repository (insecure)
--from-key-hint$RESTIC_FROM_KEY_HINTKey ID of key to try decrypting the source repository first
--from-password-command$RESTIC_FROM_PASSWORD_COMMANDShell command to obtain the source repository password from
--from-password-file$RESTIC_FROM_PASSWORD_FILEFile to read the source repository password from
--from-repo$RESTIC_FROM_REPOSITORYSource repository to copy chunker parameters from
--from-repository-file$RESTIC_FROM_REPOSITORY_FILEFile from which to read the source repository location to copy chunker parameters from
--repository-versionRepository format version to use, allowed values are a format version, latest and stable (default “stable”)

key

The “key” command allows you to set multiple access keys or passwords per repository.

Usage: restic key [command]

key add

Add a new key (password) to the repository; returns the new key ID

Usage: restic key add [flags]

OptionEnvironmentDescription
-h, --helphelp for add
--host stringthe hostname for new key
--new-insecure-no-passwordadd an empty password for the repository (insecure)
--new-password-file filefile from which to read the new password
--user stringthe username for new key

key passwd

Change key (password); creates a new key ID and removes the old key ID, returns new key ID

Usage: restic key passwd [flags]

OptionEnvironmentDescription
-h, --helphelp for add
--host stringthe hostname for new key
--new-insecure-no-passwordadd an empty password for the repository (insecure)
--new-password-file filefile from which to read the new password
--user stringthe username for new key

key list

List keys (passwords)

Usage: restic key list

key remove

Remove key ID (password) from the repository.

Usage: restic key remove [ID] [flags]

list

The “list” command allows listing objects in the repository based on type.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic list [flags] [blobs|packs|index|snapshots|keys|locks]

ls

The “ls” command lists files and directories in a snapshot.

The special snapshot ID “latest” can be used to list files and directories of the latest snapshot in the repository. The --host flag can be used in conjunction to select the latest snapshot originating from a certain host only.

File listings can optionally be filtered by directories. Any positional arguments after the snapshot ID are interpreted as absolute directory paths, and only files inside those directories will be listed. If the --recursive flag is used, then the filter will allow traversing into matching directories’ subfolders. Any directory paths specified must be absolute (starting with a path separator); paths use the forward slash ’/’ as separator.

File listings can be sorted by specifying --sort followed by one of the sort specifiers (name|size|time=mtime|atime|ctime|extension). The sorting can be reversed by specifying --reverse.

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic ls [flags] snapshotID [dir...]

OptionEnvironmentDescription
-H, --host$RESTIC_HOSTOnly consider snapshots for this host, when snapshot ID “latest” is given (can be specified multiple times)
--human-readablePrint sizes in human readable format
-l, --longUse a long listing format showing size and mode
--ncduOutput NCDU export format (pipe into ncdu -f -)
--pathOnly consider snapshots including this (absolute) path, when snapshot ID “latest” is given (can be specified multiple times)
--recursiveInclude files in subfolders of the listed directories
--reverseReverse sorted output
-s, --sortSort output by (name|size|time=mtime|atime|ctime|extension) (default name)
--tagOnly consider snapshots including tag[,tag,…], when snapshot ID “latest” is given (can be specified multiple times) (default [])

mount

The “mount” command mounts the repository via fuse to a directory. This is a read-only mount.

Snapshot Directories: If you need a different template for directories that contain snapshots, you can pass a time template via --time-template and path templates via --path-template.

Example time template without colons: --time-template "2006-01-02_15-04-05"

You need to specify a sample format for exactly the following timestamp: Mon Jan 2 15:04:05 -0700 MST 2006

For path templates, you can use the following patterns which will be replaced:

  • %i by short snapshot ID
  • %I by long snapshot ID
  • %u by username
  • %h by hostname
  • %t by tags
  • %T by timestamp as specified by --time-template

The default path templates are:

  • ids/%i
  • snapshots/%T
  • hosts/%h/%T
  • tags/%t/%T

Exit Codes:

  • Exit status is 0 if the command was successful.
  • Exit status is 1 if there was any error.
  • Exit status is 10 if the repository does not exist.
  • Exit status is 11 if the repository is already locked.
  • Exit status is 12 if the password is incorrect.

Usage: restic mount [flags] mountpoint

OptionEnvironmentDescription
--allow-otherAllow other users to access the data in the mounted directory
-H, --host$RESTIC_HOSTOnly consider snapshots for this host (can be specified multiple times)
--no-default-permissionsFor --allow-other, ignore Unix permissions and allow users to read all snapshot files
--owner-rootUse root as the owner of files and dirs
--pathOnly consider snapshots including this (absolute) path (can be specified multiple times, snapshots must include all specified paths)
--path-templateSet template for path names (can be specified multiple times)
--tagOnly consider snapshots including tag[,tag,...] (can be specified multiple times) (default [])
--time-templateSet template to use for times (default “2006-01-02T15:04:05Z07:00”)

prune

The “prune” command checks the repository and removes data that is not referenced and therefore not needed any more.

Usage: restic prune [flags]

OptionEnvironmentDescription
-n, --dry-runDo not modify the repository, just print what would be done
--max-repack-sizeStop after repacking this much data in total (allowed suffixes: k/K, m/M, g/G, t/T)
--max-unusedTolerate given limit of unused data (absolute value in bytes with suffixes k/K, m/M, g/G, t/T, a value in % or the word ‘unlimited’) (default “5%“)
--repack-cacheable-onlyOnly repack packs which are cacheable
--repack-smallRepack pack files below 80% of target pack size
--repack-smaller-thanPack below-limit packfiles (allowed suffixes: k/K, m/M)
--repack-uncompressedRepack all uncompressed data
--unsafe-recover-no-free-spaceUNSAFE, read the documentation before using! Try to recover a repository stuck with no free space. Do not use without trying ‘prune —max-repack-size 0’ first.

restore

The “restore” command extracts the data from a snapshot from the repository to a directory.

The special snapshotID “latest” can be used to restore the latest snapshot in the repository.

To only restore a specific subfolder, you can use the snapshotID:subfolder syntax, where subfolder is a path within the snapshot.

Usage: restic restore [flags] snapshotID

OptionEnvironmentDescription
--deleteDelete files from target directory if they do not exist in snapshot. Use --dry-run -vv to check what would be deleted
--dry-runDo not write any data, just show what would be done
-e, --excludeExclude a pattern (can be specified multiple times)
--exclude-fileRead exclude patterns from a file (can be specified multiple times)
--exclude-xattrExclude xattr by pattern (can be specified multiple times)
-H, --host$RESTIC_HOSTOnly consider snapshots for this host, when snapshot ID “latest” is given (can be specified multiple times)
--iexcludeSame as --exclude but ignores the casing of filenames
--iexclude-fileSame as --exclude-file but ignores casing of filenames in patterns
--iincludeSame as --include but ignores the casing of filenames
--iinclude-fileSame as --include-file but ignores casing of filenames in patterns
-i, --includeInclude a pattern (can be specified multiple times)
--include-fileRead include patterns from a file (can be specified multiple times)
--include-xattrInclude xattr by pattern (can be specified multiple times)
--overwriteOverwrite behavior, one of (always|if-changed|if-newer|never) (default always)
--pathOnly consider snapshots including this (absolute) path, when snapshot ID “latest” is given (can be specified multiple times)
--sparseRestore files as sparse
--tagOnly consider snapshots including tag[,tag,...], when snapshot ID “latest” is given (can be specified multiple times) (default [])
-t, --targetDirectory to extract data to
--verifyVerify restored files content

rewrite

The “rewrite” command excludes files from existing snapshots. It creates new snapshots containing the same data as the original ones, but without the files you specify to exclude. All metadata (time, host, tags) will be preserved.

The snapshots to rewrite are specified using the --host, --tag and --path options, or by providing a list of snapshot IDs. Please note that specifying neither any of these options nor a snapshot ID will cause the command to rewrite all snapshots.

The special tag ‘rewrite’ will be added to the new snapshots to distinguish them from the original ones, unless --forget is used. If the --forget option is used, the original snapshots will instead be directly removed from the repository.

Please note that the --forget option only removes the snapshots and not the actual data stored in the repository. In order to delete the no longer referenced data, use the “prune” command.

When rewrite is used with the --snapshot-summary option, a new snapshot is created containing statistics summary data. Only two fields in the summary will be non-zero: TotalFilesProcessed and TotalBytesProcessed.

When rewrite is called with one of the --exclude options, TotalFilesProcessed and TotalBytesProcessed will be updated in the snapshot summary.

Usage: restic rewrite [flags] [snapshotID ...]

OptionEnvironmentDescription
-n, --dry-runDo not do anything, just print what would be done
-e, --excludeExclude a pattern (can be specified multiple times)
--exclude-fileRead exclude patterns from a file (can be specified multiple times)
--forgetRemove original snapshots after creating new ones
-H, --host$RESTIC_HOSTOnly consider snapshots for this host (can be specified multiple times)
--iexcludeSame as --exclude but ignores the casing of filenames
--iexclude-fileSame as --exclude-file but ignores casing of filenames in patterns
--new-hostReplace hostname
--new-timeReplace time of the backup
--pathOnly consider snapshots including this (absolute) path (can be specified multiple times; snapshots must include all specified paths)
-s, --snapshot-summaryCreate snapshot summary record if it does not exist
--tagOnly consider snapshots including tag[,tag,…] (can be specified multiple times) (default: [])

snapshots

The “snapshots” command lists all snapshots stored in the repository.

Usage: restic snapshots [flags] [snapshotID ...]

OptionEnvironmentDescription
-c, --compactuse compact output format
-g, --group-by groupgroup snapshots by host, paths and/or tags, separated by comma
-H, --host host$RESTIC_HOSTonly consider snapshots for this host (can be specified multiple times)
--latest nonly show the last n snapshots for each host and path
--path pathonly consider snapshots including this (absolute) path (can be specified multiple times, snapshots must include all specified paths)
--tag tag[,tag,...]only consider snapshots including tag[,tag,...] (can be specified multiple times) (default [])

stats

The “stats” command walks one or multiple snapshots in a repository and accumulates statistics about the data stored therein. It reports on the number of unique files and their sizes, according to one of the counting modes as given by the --mode flag.

It operates on all snapshots matching the selection criteria or all snapshots if nothing is specified. The special snapshot ID “latest” is also supported. Some modes make more sense over just a single snapshot, while others are useful across all snapshots, depending on what you are trying to calculate.

The modes are:

  • restore-size: (default) Counts the size of the restored files.
  • files-by-contents: Counts total size of unique files, where a file is considered unique if it has unique contents.
  • raw-data: Counts the size of blobs in the repository, regardless of how many files reference them.
  • blobs-per-file: A combination of files-by-contents and raw-data.

Refer to the online manual for more details about each mode.

Usage: restic stats [flags] [snapshot ID] [...]

OptionEnvironmentDescription
-H, --host host$RESTIC_HOSTonly consider snapshots for this host (can be specified multiple times)
--mode stringcounting mode: restore-size (default), files-by-contents, blobs-per-file or raw-data (default “restore-size”)
--path pathonly consider snapshots including this (absolute) path (can be specified multiple times, snapshots must include all specified paths)
--tag tag[,tag,...]only consider snapshots including tag[,tag,...] (can be specified multiple times) (default [])

tag

The “tag” command allows you to modify tags on exiting snapshots.

You can either set/replace the entire set of tags on a snapshot, or add tags to/remove tags from the existing set.

When no snapshotID is given, all snapshots matching the host, tag and path filter criteria are modified.

Usage: restic tag [flags] [snapshotID ...]

OptionEnvironmentDescription
--add tagstags which will be added to the existing tags in the format tag[,tag,...] (can be given multiple times) (default [])
-H, --host host$RESTIC_HOSTonly consider snapshots for this host (can be specified multiple times) (default: $RESTIC_HOST)
--path pathonly consider snapshots including this (absolute) path (can be specified multiple times, snapshots must include all specified paths)
--remove tagstags which will be removed from the existing tags in the format tag[,tag,...] (can be given multiple times) (default [])
--set tagstags which will replace the existing tags in the format tag[,tag,...] (can be given multiple times) (default [])
--tag tag[,tag,...]only consider snapshots including tag[,tag,…] (can be specified multiple times) (default [])

unlock

The “unlock” command removes stale locks that have been created by other restic processes.

Usage: restic unlock [--remove-all] [flags]