Duplicity creates incremental backups by default, which means each backup after the initial full backup only stores changes. To restore from a specific date, you need to understand how Duplicity organizes these backups:
duplicity collection-status file:///path/to/backup
This command will list all available backup sets with their timestamps, allowing you to identify the exact point you want to restore from.
The most straightforward method is using the --time
parameter:
duplicity --time "3 days ago" file:///path/to/backup /path/to/restore
You can specify exact dates in various formats:
duplicity --time 2023-11-15 file:///backup /restore
duplicity --time "2023-11-15 14:30" file:///backup /restore
It's good practice to verify what will be restored first:
duplicity verify --time "3 days ago" file:///backup /target/directory
To restore individual files from a specific date:
duplicity --file-to-restore path/to/file --time "2023-11-15" file:///backup /restore/location
For remote backups (like S3 or SSH), the syntax remains similar:
duplicity --time "1 week ago" s3://s3.amazonaws.com/bucket_name/prefix /restore/path
Here's a bash script example for automated restoration:
#!/bin/bash
RESTORE_DATE=$(date -d "3 days ago" +%Y-%m-%d)
duplicity --time $RESTORE_DATE file:///backup /restore
If you encounter errors about missing chain files, try:
duplicity cleanup --force file:///backup
Then attempt the restoration again.
For large backups, consider these options:
duplicity --time "2023-11-15" --num-retries 3 --volsize 100 file:///backup /restore
The --volsize
parameter (in MB) can help with network transfers, and --num-retries
handles temporary failures.
Duplicity organizes backups as a chain of incremental backups with periodic full backups. Each backup set contains metadata about when it was created, allowing for precise time-based restoration.
First, you'll want to inspect your backup repository to see what recovery points are available:
duplicity collection-status file:///path/to/backup
# or for remote backups:
duplicity collection-status s3://bucket-name/path
This command outputs a timeline of available backups with their timestamps, similar to:
Full backup set 1 (2023-11-01 00:00:00)
Incremental backup set 2 (2023-11-02 00:00:00)
Incremental backup set 3 (2023-11-03 00:00:00)
Incremental backup set 4 (2023-11-04 00:00:00)
The basic command structure for restoring from a specific date is:
duplicity --time "3 days ago" file:///path/to/backup /path/to/restore
Duplicity accepts various time formats for the --time
parameter:
- "2023-11-01" (specific date)
- "3 days ago" (relative time)
- "2023-11-01 14:30:00" (exact timestamp)
To restore your entire backup from exactly three days ago:
duplicity --time "3 days ago" \
--no-encryption \
sftp://user@backup-server//backups/home \
/home/restored-backup
For restoring just a specific file as it existed three days ago:
duplicity --time "3 days ago" \
--file-to-restore /path/to/specific/file \
file:///backup/location \
/destination/for/restored/file
You can use more precise time specifications for critical recovery scenarios:
# Restore from specific hour and minute
duplicity --time "2023-11-01 14:30" s3://bucket /restore
# Restore from before a specific event
duplicity --time "2023-11-01T14:30:00-05:00" scp://user@host/path /restore
After restoration, verify the files were restored from the correct point in time:
duplicity verify --time "3 days ago" file:///backup /restored/path
This compares checksums of restored files against the backup archive to ensure integrity.
For scripted recovery operations, consider this bash function:
#!/bin/bash
restore_from_days_ago() {
local days=$1
local source=$2
local dest=$3
echo "Restoring backup from $days days ago..."
duplicity --time "$days days ago" "$source" "$dest"
if [ $? -eq 0 ]; then
echo "Restore completed successfully"
else
echo "Restore failed" >&2
return 1
fi
}