Restic: FS Backup/Recovery
While Pigsty handles PostgreSQL database backup and recovery, how do we handle backup and recovery for regular files and directories?
For various business applications using PostgreSQL (such as Odoo, GitLab), you can use Restic to regularly backup file system data (e.g., /data/odoo
).
Restic is an excellent open-source backup tool that supports snapshots, incremental backups, encryption, compression, and can use various services including S3/MinIO as backup repositories. For detailed information, please refer to the restic documentation.
Quick Start
Pigsty Infra repository provides ready-to-use latest Restic RPM/DEB packages, while most Linux distributions’ official repositories offer older versions.
yum install -y restic
apt install -y restic
For demonstration purposes, we’ll use a local directory as the backup repository. Repository initialization only needs to be done once:
mkdir -p /data/backups/restic
export RESTIC_REPOSITORY=/data/backups/restic
export RESTIC_PASSWORD=some-strong-password
restic init
Next, you can perform backup operations, view snapshots, and restore files:
restic backup /www/web.cc # Backup /www/web.cc directory to repository
restic snapshots # List backup snapshots
restic restore -t /tmp/web.cc 0b11f778 # Restore snapshot 0b11f778 to /tmp/web.cc
restic check # Regularly check repository integrity
Complete Command Output
$ restic backup /www/web.cc
repository fcd37256 opened (repository version 2) successfully, password is correct
created new cache in /root/.cache/restic
no parent snapshot found, will read all files
Files: 5934 new, 0 changed, 0 unmodified
Dirs: 1622 new, 0 changed, 0 unmodified
Added to the repository: 1.570 GiB (1.167 GiB stored)
processed 5934 files, 1.694 GiB in 0:20
snapshot 0b11f778 saved
$ restic snapshots # View backup snapshots
repository fcd37256 opened (repository version 2) successfully, password is correct
ID Time Host Tags Paths
------------------------------------------------------------------
0b11f778 2025-03-19 15:25:21 pigsty.cc /www/web.cc
------------------------------------------------------------------
1 snapshots
$ restic backup /www/web.cc
repository fcd37256 opened (repository version 2) successfully, password is correct
using parent snapshot 0b11f778
Files: 0 new, 0 changed, 5934 unmodified
Dirs: 0 new, 0 changed, 1622 unmodified
Added to the repository: 0 B (0 B stored)
processed 5934 files, 1.694 GiB in 0:00
snapshot 06cd9b5c saved
[03-19 15:25:59] [email protected]:/data/backups
$ restic snapshots # View backup snapshots
repository fcd37256 opened (repository version 2) successfully, password is correct
ID Time Host Tags Paths
------------------------------------------------------------------
0b11f778 2025-03-19 15:25:21 pigsty.cc /www/web.cc
06cd9b5c 2025-03-19 15:25:58 pigsty.cc /www/web.cc
------------------------------------------------------------------
2 snapshots
$ restic restore -t /www/web.cc 0b11f778
repository fcd37256 opened (repository version 2) successfully, password is correct
restoring <Snapshot 0b11f778 of [/www/web.cc] at 2025-03-19 15:25:21.514089814 +0800 HKT by [email protected]> to /www/web.cc
Using Object Storage
You can use various methods to store Restic backup data. Here’s how to use Pigsty’s built-in MinIO as a backup repository.
export AWS_ACCESS_KEY_ID=minioadmin # Default MinIO account
export AWS_SECRET_ACCESS_KEY=minioadmin # Default MinIO password
restic -r s3:http://sss.pigsty:9000/infra init # Use the default infra bucket as backup destination
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.