How to restore files from an rsync backup

Restoring a file from an rsync backup directly into the live path can replace newer data or hide which snapshot supplied the recovery. A separate recovery directory keeps the restored copy available for inspection before any application, user home, or service directory is touched.

The rsync command can restore from a local backup tree, mounted backup volume, or remote rsync source using the same source-to-destination pattern used for backups. The --archive option preserves common file metadata, while --relative with a /./ marker keeps only the path segment after that marker under the recovery root.

Use a dry run before the restore when the source path is long or the backup contains multiple similar snapshots. A dry run with --itemize-changes shows the directories and file that rsync would create, and the final checksum or metadata check confirms that the recovered copy matches the backup copy before it is handed back to the owner.

Steps to restore files from an rsync backup:

  1. Choose the backup file and recovery root before running rsync.

    Example backup file: /backups/2026-06-06/home/alex/docs/report.txt. Example recovery root: /srv/recovery/2026-06-06/. The /./ marker in later commands tells rsync to preserve only home/alex/docs/report.txt below the recovery root.

  2. Create the recovery root with restricted directory permissions.
    $ sudo install -d -m 0750 /srv/recovery/2026-06-06
  3. Preview the restore into the recovery root.
    $ sudo rsync --archive --relative --dry-run --itemize-changes /backups/2026-06-06/./home/alex/docs/report.txt /srv/recovery/2026-06-06/
    cd+++++++++ home/
    cd+++++++++ home/alex/
    cd+++++++++ home/alex/docs/
    >f+++++++++ home/alex/docs/report.txt

    No file is copied during the dry run. The itemized output shows the parent directories and restored file that would be created under the recovery root.

  4. Run the restore after the preview shows only the expected path.
    $ sudo rsync --archive --relative --itemize-changes /backups/2026-06-06/./home/alex/docs/report.txt /srv/recovery/2026-06-06/
    cd+++++++++ home/
    cd+++++++++ home/alex/
    cd+++++++++ home/alex/docs/
    >f+++++++++ home/alex/docs/report.txt

    Do not add --delete or point the destination at a live directory unless the restore plan explicitly requires replacing existing data.

  5. Compare checksums between the backup file and restored file.
    $ sudo sha256sum /backups/2026-06-06/home/alex/docs/report.txt /srv/recovery/2026-06-06/home/alex/docs/report.txt
    490e4e7624d80301d70f2ffd1776aa2fd03e2a7f0db74c9dce733002a09283c0  /backups/2026-06-06/home/alex/docs/report.txt
    490e4e7624d80301d70f2ffd1776aa2fd03e2a7f0db74c9dce733002a09283c0  /srv/recovery/2026-06-06/home/alex/docs/report.txt
  6. Check ownership, mode, and size when metadata matters for the restored file.
    $ sudo stat -c '%n %U:%G %a %s bytes' /backups/2026-06-06/home/alex/docs/report.txt /srv/recovery/2026-06-06/home/alex/docs/report.txt
    /backups/2026-06-06/home/alex/docs/report.txt root:root 640 40 bytes
    /srv/recovery/2026-06-06/home/alex/docs/report.txt root:root 640 40 bytes

    The restored copy is ready for owner review or for the separate application-specific step that returns it to service.