Iteratively Backing Up To A Remote Computer Using FTP
This tutorial will show you how to back up your files to a remote computer in an encrypted format using duplicity.
Steps
Install duplicity if you haven't already
sudo apt-get install duplicity -y
Copy and paste the following BASH backup script onto the server and edit your settings/variables appropriately.
#!/bin/bash
# A simple backup script wrapper for duplicity.
# Author - nixCraft under GPL v2+
# Edited by Programster
# On ubuntu
# -----------------------------------------------------
# Put your ftp password here for duplicity to be able to automatically login/proceed.
export FTP_PASSWORD=xxxxx
# Specify your FTP user.
FTP_USER="programster"
# Specify the host of your FTP account
FTP_HOST="ftp.mydomain.com"
# Specify the path on your ftp host where you want the backups to go.
# Be sure to end with a /. if you want the folders to be within the folder you named.
FTP_STORAGE_PATH="/Backups/name-of-backup-folder/."
# The path to where the files that we want to backup are
SOURCE='/path/to/folder/to/backup'
# The target string to provide duplicity of where to store the backup
TARGET="ftp://${FTP_USER}@${FTP_HOST}${FTP_STORAGE_PATH}"
# The full path to the duplicity program
# you shouldn't need to change this if you are using Ubuntu
DUPLICITY_CMD='/usr/bin/duplicity'
# Specify how far back we want to be able to restore to
# e.g. how long a backup lives in days before it is removed.
BACKUP_LIFETIME="30D"
# Specify how many days of iterative backups are allowed to
# be taken before a full backup has to be taken
DAYS_BETWEEN_FULL_BACKUPS="10D"
####################
# Removing old backups
echo "Removing old backups..."
$DUPLICITY_CMD remove-older-than ${BACKUP_LIFETIME} ${TARGET}
# Backup our files
echo "Backing up files..."
$DUPLICITY_CMD ${SOURCE} --full-if-older-than ${DAYS_BETWEEN_FULL_BACKUPS} --no-encryption ${TARGET}
echo "done!"
Now run your backup script and you should get output similar to below:
Last full backup date: none
No signatures found, switching to full backup.
--------------[ Backup Statistics ]--------------
StartTime 1494703857.24 (Sat May 13 14:30:57 2017)
EndTime 1494703857.25 (Sat May 13 14:30:57 2017)
ElapsedTime 0.02 (0.02 seconds)
this is another file
SourceFiles 2
SourceFileSize 4108 (4.01 KB)
NewFiles 2
NewFileSize 4108 (4.01 KB)
DeletedFiles 0
ChangedFiles 0
ChangedFileSize 0 (0 bytes)
ChangedDeltaSize 0 (0 bytes)
DeltaEntries 2
RawDeltaSize 12 (12 bytes)
TotalDestinationSizeChange 521 (521 bytes)
Errors 0
-------------------------------------------------
Congratulations, you now have a remote backup!
Checking It Worked
If you ftp into the remote server's backup area, you should now see a bunch of encrypted gpg files like below:
duplicity-full.20170513T193057Z.manifest.gpg
duplicity-full.20170513T193057Z.vol1.difftar.gpg
duplicity-full-signatures.20170513T193057Z.sigtar.gpg
duplicity-inc.20170513T193057Z.to.20170513T193126Z.manifest.gpg
duplicity-inc.20170513T193057Z.to.20170513T193126Z.vol1.difftar.gpg
duplicity-new-signatures.20170513T193057Z.to.20170513T193126Z.sigtar.gpg
Also, if you run the following command, you can see all the backups you have got:
TARGET="ftp://${FTP_USER}@${FTP_HOST}${FTP_STORAGE_PATH}"
duplicity collection-status ${TARGET}
Last full backup date: Fri Feb 26 19:23:07 2021
Collection Status
-----------------
Connecting with backend: BackendWrapper
Archive directory: /home/programster/.cache/duplicity/423e0f105fe7a57fc4e0caf611ff17cb
Found 0 secondary backup chains.
Found primary backup chain with matching signature chain:
-------------------------
Chain start time: Fri Feb 26 19:23:07 2021
Chain end time: Fri Feb 26 19:26:02 2021
Number of contained backup sets: 4
Total number of contained volumes: 4
Type of backup set: Time: Number of volumes:
Full Fri Feb 26 19:23:07 2021 1
Incremental Fri Feb 26 19:23:49 2021 1
Incremental Fri Feb 26 19:24:17 2021 1
Incremental Fri Feb 26 19:26:02 2021 1
-------------------------
No orphaned or incomplete backup sets found.
References
First published: 27th February 2021