هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
RESTIC_REPOSITORY=s3:https://s3.example.com/backups/web1
RESTIC_PASSWORD_FILE=/etc/restic/password
AWS_ACCESS_KEY_ID=<backup user key>
AWS_SECRET_ACCESS_KEY=<backup user secret>Step by step
- Install (
dnf install resticfrom EPEL, orapt-get install restic) and create the secret files:
install -d -m 700 /etc/restic
(umask 077; openssl rand -base64 32 > /etc/restic/password)
chmod 600 /etc/restic/envStore a copy of the repository password outside the server (password manager). Without it, nobody can ever read the backup — also not you.
- Initialise the repository once (quick answer). Use a backup user with access only to its own bucket/path.
- What to back up: configs (
/etc), app data (/srv,/var/www), and database dumps (not the live database files):
- Retention — keep 7 daily, 4 weekly, 12 monthly snapshots, free the space:
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune- Restore — one folder into a test path, or one file:
restic snapshots --tag files
restic restore latest --tag files --target /tmp/restore --include /etc/nginx
restic dump latest --tag postgres shop.dump > /tmp/shop.dump- Run it every night — a systemd service + timer:
[Unit]
Description=restic backup
[Service]
Type=oneshot
EnvironmentFile=/etc/restic/env
ExecStart=/usr/bin/restic backup /etc /srv /var/www --one-file-system --tag files
ExecStartPost=/usr/bin/restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 12 --prune
Nice=10
IOSchedulingClass=idleAdd a restic-backup.timer with OnCalendar=*-*-* 02:15:00 and Persistent=true, then systemctl enable --now restic-backup.timer. Alert when it fails (a push monitor in Uptime Kuma, or a Prometheus textfile metric).
- Check the repository now and then:
restic check
restic check --read-data-subset=5%Check that it worked
restic snapshots shows a new snapshot every day, restic check has no errors, and a test restore (monthly) gives you the files and a database dump that restores.
Common problems
| Problem | Cause | Fix |
|---|---|---|
Fatal: unable to open config file: … Is there a repository at the following location? | Not initialised, or wrong RESTIC_REPOSITORY. | restic init once; check the URL. |
wrong password or no key found | Wrong password file. | Use the original password — there is no reset. |
unable to create lock … repository is already locked | Another run, or a crashed run left a lock. | Wait; then restic unlock if no run is active. |
| Backup is huge / slow | It walks caches, mounts or /proc. | --one-file-system, --exclude-caches, an exclude file. |
| Database restore fails | The live DB files were copied while running. | Back up a dump (pg_dump, mysqldump) through --stdin. |
| Nobody noticed backups stopped | No alert. | Alert on failure and on "no snapshot in 26 hours". |
Go further
- Command pages: systemctl, openssl.
- Next how-tos: Back up and restore PostgreSQL, Create a systemd timer, Copy files to and from S3, Store files in MinIO with the S3 API.
- Full guide: Install and use restic. Storage: MinIO. At work: Backups and the 3-2-1 rule.
- Practise: Lab: prove the backup restores.
1What happens if you lose the restic repository password?
The backup can never be read again — keep a copy of the password outside the server.
2Why back up a database dump instead of the database's data files?
Files copied while the database runs can be inconsistent; a dump is a consistent copy.