rustic is an efficient, open-source incremental backup tool implemented in Rust based on the restic protocol, with fast speed and strong performance. It can handle backing up large numbers of files while excluding unnecessary directories. This article documents my experience using it to back up important files on my Windows computer.

Installation (Windows)

It is recommended to manage rustic via scoop

# If scoop is not yet installed
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

# Install rustic
scoop install rustic

Cross-Drive Backup

My backup location is on a portable hard drive E drive (drive letter may not be fixed), and the backup target is the user directory under C drive. Using Windows paths with drive letters and colons in rustic command line fails. You can create a symbolic link (DISK_C) in the E drive root directory pointing to C drive, and then use /DISK_C in commands to represent the C drive.

  • Open Command Prompt in Administrator mode.
  • Switch to the backup drive (e.g., E drive) root directory
  • Create the link: mklink /D DISK_C C:\
  • Now you can use the elegant path format \DISK_C in the command line to access the C drive content, perfectly avoiding path parsing issues caused by drive letters.

Initialize Repository

Create a dedicated folder for the repository on the backup drive and run initialization:

rustic init
  • Tip: Rustic's working logic is similar to git.

Create a configuration file in that directory, so you don't need to specify the configuration file path in future commands:

# rustic.toml
[repository]
# Repository location, similar to .git
repository = "./repo"
# Password
password = ""

Excluding Directories

  • If the backup target contains many git project directories, you can use the --git-ignore parameter
  • --git-ignore requires a .git directory to exist to work.
  • You can use --glob-file to specify a file with glob syntax.
  • You can use both --glob-file and --git-ignore together.
  • If you want to use --git-ignore but also include some files excluded by .gitignore, it's not possible. It is recommended to not use --git-ignore in this case, and instead add some commonly excluded large directory rules in --glob-file.
  • When using # for comments in the glob rules file, do not write rules on the same line as comments.
  • It is only recommended to use exclusion rules in the glob rules file.
  • !**/a/b/: Exclude the a/b directory at any depth precisely.

Example glob file:

# Write exclusion rules here, note that # comments need to be on their own line
!node_modules/
!**/target/debug/
!.venv/
!site-package/
!__pycache__/

Which Directories to Exclude?

If you are backing up the Windows user folder and don't know what can be excluded, you can use treesize software to check each directory one by one. This software has a free green (portable) version.

Starting Backup

Before performing a real backup, please be sure to do a "drill":

  • Dry Run: rustic backup \DISK_C\Users\Username\ --glob-file=main.glob.txt -n Estimate the backup file size by observing it to confirm if the configuration is correct. Remove the -n parameter to actually perform the operation.
  • Common management commands:
    • View all snapshots: rustic snapshots
    • List files in a specific snapshot, snapshot ID can be like git (just write the first few characters): rustic ls <snapshot ID>
    • List files at a specific path in a snapshot: rustic ls <snapshot ID>:path
    • Of course, you can use latest to represent the latest snapshot ID, which is especially useful when there is only one backup task.

Restoring Files

  • It is recommended to restore to a new empty directory: rustic restore <snapshot ID> <target folder>
  • Similarly, you can restore only a specific path: rustic restore <snapshot ID>:path <target folder>
  • Browse snapshots with file manager:
    • Run continuously: rustic webdav <snapshot ID>
    • Open Windows File Explorer, enter the address and press Enter (8000 is the port number from the previous step's output): \\localhost:8000\DavWWWRoot\

Deleting Snapshots

  • Pay attention to the chronological order of snapshots, don't delete the latest one: rustic forget <snapshot ID>
  • The above only marks for deletion, this step actually frees up space: rustic prune