Programster's Blog

Tutorials focusing on Linux, programming, and open-source

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.


Install duplicity if you haven't already

sudo apt-get install duplicity -y

If using Ubuntu, you may wish to install Duplicity from the PPA.

Copy and paste the following BASH backup script onto the server and edit your settings/variables appropriately.


# 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.

# Specify the host of your FTP account

# 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.

# The path to where the files that we want to backup are

# The target string to provide duplicity of where to store the backup

# The full path to the duplicity program
# you shouldn't need to change this if you are using Ubuntu

# 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.

# Specify how many days of iterative backups are allowed to
# be taken before a full backup has to be taken


# Removing old backups
echo "Removing old backups..."

# 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:


Also, if you run the following command, you can see all the backups you have got:

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.


Last updated: 13th November 2022
First published: 27th February 2021