How to Restore a Single File from a Full Backup

Sometimes you don't need a full server restore — just one specific file that was accidentally deleted or corrupted. This guide covers efficiently extracting a single file from various backup formats.

Why This Matters

A full restore is often overkill (and riskier, since it affects everything) when you actually just need one specific file back — understanding how to extract selectively saves time and avoids unnecessary disruption to everything else.

Restoring from a tar-Based Backup

tar -tzvf backup.tar.gz | grep filename

First locate the exact path within the archive, then extract just that specific file:

tar -xzvf backup.tar.gz path/to/specific/file.txt

Restoring from an rsync-Based Backup

If your backup approach uses rsync to a separate location (see rsync-based backup guides), simply copy the specific file directly from the backup location:

cp /backup/location/path/to/file.txt /original/location/

Restoring a Single File from a Database Backup

This is more involved — a database "file" (a specific record/row) isn't typically extractable as cleanly as a file system file. Options: restore the full dump to a temporary separate database, then export just the needed data from there:

pg_restore -d temp_restore_db backup.dump
pg_dump -t specific_table -d temp_restore_db > single_table.sql

Restoring a Single File from a VPS Provider Snapshot

See How to Use VPS Provider Snapshots Effectively — typically requires either restoring the snapshot to a separate temporary server/volume (then extracting the specific file and discarding the temporary instance), or, if your provider supports it, mounting the snapshot directly for selective file access.

Restoring a Single File from Object Storage Backups

aws s3 cp s3://your-bucket/backups/path/to/file.txt ./restored-file.txt

Object storage-based backups (see How to Back Up to Object Storage (S3-Compatible)) often support direct selective retrieval without needing to download an entire archive first.

Restoring a Single File from a Docker Volume Backup

docker run --rm -v myvolume:/data -v $(pwd):/backup alpine \
  sh -c "cd /data && tar -xzf /backup/volume-backup.tar.gz path/to/specific/file"

Verifying the Restored File Before Replacing the Original

Before overwriting a current (possibly still-needed) version, verify the restored file is genuinely what you expect — check content, timestamp, and size for reasonableness before committing to the replacement.

Backing Up the Current State Before Overwriting

cp /current/location/file.txt /current/location/file.txt.before-restore

A quick safety measure — if the current version turns out to have been needed after all, you haven't lost it by overwriting without any fallback.

When Selective Restoration Isn't Straightforward

Some backup formats/tools don't support efficient selective extraction (particularly certain proprietary or heavily-compressed formats) — if you find yourself needing this capability frequently, consider whether your backup tooling/format choice should factor in this specific need going forward.

Common Errors

Extracted file has unexpected permissions/ownership — verify and correct file ownership/permissions after extraction, since archive extraction doesn't always preserve these exactly as needed for the file's actual intended location.

Continue Reading

Browse more articles in Backup & Disaster Recovery.

  • restore single file backup, extract file from tar backup, selective file restore, recover one file from backup
  • 0 gebruikers vonden dit artikel nuttig
Was dit antwoord nuttig?

Gerelateerde artikelen

Backup Strategy 101: The 3-2-1 Rule Explained

Before diving into specific backup tools, it's worth understanding the industry-standard...

How to Back Up to Object Storage (S3-Compatible)

S3-compatible object storage provides durable, cost-effective off-site backup storage —...

How to Test and Verify Your Backups Actually Work

A backup that has never been restored is not a verified backup — it's an assumption. This...

How to Create a Disaster Recovery Plan for Your VPS

A disaster recovery (DR) plan is a documented, tested procedure for restoring service after a...

How to Use VPS Provider Snapshots Effectively

Most VPS providers offer a snapshot feature — a point-in-time image of your entire server....