Home > linux, system administration > Backup script: encrypted, offsite, incremental backup (rsync, rdiff-backup, encfs)

Backup script: encrypted, offsite, incremental backup (rsync, rdiff-backup, encfs)

In this post I will explain a small (~100 lines) backup script I use to make offsite automated backups of several computers.

Overview of the scripts’ actions

  1. Mount a local folder using encfs (the backup files are written in this folder)
  2. Do an incremental backup with the local encfs folder from step one as the destination. Using rdiff-backup with a remote location as the target sometimes resulted in failed/broken backups on systems that frequently go offline. (laptops)
  3. Send the encrypted files to an off-site server (any server with ssh access will do, I use the quite cheap datastorageunit.com servers.
  4. Send all logged events and an overview of the incremental backups over email

The script depends on several tools that should be available on most linux distributions:

  • ‘rdiff-backup’ for incremental backups
  • ‘rsync’ for bandwidth efficient file transfers
  • ‘encfs’ for encrypted storage
  • ‘sendemail’ for error reporting

Script: link (rename .doc file to .sh file) (.sh file upload is not allowed at wordpress.com)

A small C++ application is needed to automount the encfs folder: source


int main()
{
std::cout << "myinsecurepassword" << std::endl;
return 0;
}

Example logfile:
============================================================================
Fri Dec 31 00:30:34 CET 2010
============================================================================
1. Mounting datastor encrypted folder
encfs mounted ok
2. Starting local rdiff backup
--------------[ Session statistics ]--------------
StartTime 1293751834.00 (Fri Dec 31 00:30:34 2010)
EndTime 1293751844.85 (Fri Dec 31 00:30:44 2010)
ElapsedTime 10.85 (10.85 seconds)
SourceFiles 25556
SourceFileSize 3455095493 (3.22 GB)
MirrorFiles 25556
MirrorFileSize 3455092469 (3.22 GB)
NewFiles 0
NewFileSize 0 (0 bytes)
DeletedFiles 0
DeletedFileSize 0 (0 bytes)
ChangedFiles 6
ChangedSourceSize 16679 (16.3 KB)
ChangedMirrorSize 13655 (13.3 KB)
IncrementFiles 11
IncrementFileSize 737 (737 bytes)
TotalDestinationSizeChange 3761 (3.67 KB)
Errors 0
--------------------------------------------------
3. Local rdiff backup: deleting old files
4. Local rdiff backup: listing backupsets
Local rdiff-backup took 59 seconds.
5. Sanity check: encfs mounted ok
6. Backup using rsync starting here
7. Backup to datastorageunit finished
Rsync to off-site server took 185 seconds.
Total backup took 197 seconds.
============================================================================

Advertisements
  1. 21 June 2013 at 11:03 am

    There are many details that need to be addressed
    when making an auto purchase. If you are unaware of these details, you could find
    yourself overpaying for the car that is not right for you.
    You will find some great advice in the article that follows
    that will assist you in purchasing your next car.

  2. 30 June 2013 at 8:32 am

    For most up-to-date news you have to visit world wide web and on the
    web I found this site as a best site for newest updates.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: