Git Product home page Git Product logo

zertrin / duplicity-backup.sh Goto Github PK

View Code? Open in Web Editor NEW

This project forked from orkaa/dt-s3-backup

766.0 49.0 189.0 378 KB

Bash wrapper script for automated backups with duplicity supporting Amazon's S3 online storage as well as other storage destinations (ftp, rsync, sftp, local storage...).

Home Page: https://zertrin.org/projects/duplicity-backup/

License: GNU General Public License v3.0

Shell 100.00%
backup backup-script duplicity amazon-s3

duplicity-backup.sh's Introduction

Maintenance

Note: As of 2019, I do not intend to maintain this tool further myself. Feel free to fork it if you want. If a well maintained fork appears, let me know so I can link to it from here.

Build Status

duplicity-backup.sh

This bash script was designed to automate and simplify the remote backup process of duplicity on Amazon S3 primarily. Other backup destinations are possible (Google Cloud Storage, FTP, SFTP, SCP, rsync, file...), i.e. any of duplicity's supported outputs.

After your script is configured, you can easily backup, restore, verify and clean (either via cron or manually) your data without having to remember lots of different command options and passphrases.

Most importantly, you can easily backup the script and your gpg key in a convenient passphrase-encrypted file. This comes in in handy if/when your machine ever does go belly up.

Optionally, you can set up an email address where the log file will be sent, which is useful when the script is used via cron.

This version is a rewriting of the code originally written by Damon Timm, including many patches that have been brought to the original scripts by various forks on Github. Thanks to all the contributors!

More information about this script is available at https://zertrin.org/projects/duplicity-backup/

The original version of the code is available at https://github.com/theterran/dt-s3-backup

duplicity-backup.sh IS NOT duplicity

It is only a wrapper script for duplicity written in bash!

This means the following:

  • You need to install AND configure duplicity BEFORE using duplicity-backup.sh
  • The official documentation of duplicity is relevant to duplicity-backup.sh too. Virtually any option supported by duplicity can be specified in the config file of duplicity-backup.sh. See the STATIC_OPTIONS, CLEAN_UP_TYPE and CLEAN_UP_VARIABLE parameters in particular.
  • Before asking something about duplicity-backup.sh, ensure that your question isn’t actually concerning duplicity ;) First, make sure you can perform a backup with duplicity without using this script. If you can't make the backup work with duplicity alone, the problem is probably concerning duplicity and not this script. If you manage to make a backup with duplicity alone but not with this script, then there is probably a problem with duplicity-backup.sh.
  • In particular, to the question "Does duplicity-backup.sh support the backend XXX" (with XXX being for example Amazon Glacier), the answer is always the same: "duplicity-backup.sh uses duplicity, so ask the developers of duplicity ;) Once it's in duplicity, it's automatically available to duplicity-backup.sh"

Contributing

The development version of the code is available at https://github.com/zertrin/duplicity-backup.sh in the dev branch. It is a bleeding-edge version with the latest changes that have not yet been tested a lot, but that's the best starting point to contribute.

Pull requests are welcome! However please always use individual feature branches for each pull request. I may not accept a pull request from a master or dev branch.

Here is how to do it:

Fork the repository first and then clone your fork on your machine:

git clone [email protected]:YOURNAME/duplicity-backup.sh.git duplicity-backup
cd duplicity-backup

Add a remote for the upstream repository:

git remote add upstream [email protected]:zertrin/duplicity-backup.sh.git
git fetch upstream

Create a new topic branch for the changes you want to make, based on the dev branch from upstream:

git checkout -b my-fix-1 upstream/dev

Make your changes, test them, commit them and push them to Github:

git push origin my-fix-1

Open a Pull request from YOURNAME:my-fix-1 to zertrin:dev.

If you want to open another pull request for another change which is independent of the previous one, just create another topic branch based on master (git checkout -b my-fix-2 upstream/dev)

Installation

1. Get the script

You can clone the repository (which makes it easy to get future updates):

git clone https://github.com/zertrin/duplicity-backup.sh.git duplicity-backup

If you prefer the stable (but old) version do:

git checkout stable

... or if you want the normal version, then:

git checkout master

... or if you like living on the edge (or need the latest bugfixes), you can stay at the development version which is automatically cloned.

Or just download the ZIP file:

Version Download link
stable (old) https://github.com/zertrin/duplicity-backup.sh/archive/stable.zip
normal https://github.com/zertrin/duplicity-backup.sh/archive/master.zip
latest https://github.com/zertrin/duplicity-backup.sh/archive/dev.zip

2. Configure the script

This script requires user configuration. Instructions are in the config file itself and should be self-explanatory. You SHOULD NOT edit the example config file duplicity-backup.conf.example, but instead make a copy of it (for example to /etc/duplicity-backup.conf) and edit this one.

Be sure to replace all the foobar values with your real ones. Almost every value needs to be configured in someway.

The script looks for its configuration by reading the path to the config file specified by the command line option -c or --config (see Usage)

If no config file was given on the command line, the script will try to find the file specified in the CONFIG parameter at the beginning of the script (default: duplicity-backup.conf in the script's directory).

So be sure to either:

  • specify the configuration file path on the command line with the -c option [recommended]
  • or to edit the CONFIG parameter in the script to match the actual location of your config file. [deprecated] (will be removed in future versions of the script)

NOTE: to ease future updates of the script, you may prefer NOT to edit the script at all and to specify systematically the path to your config file on the command line with the -c or --config option.

You can use one copy of the script and call it with different config file for different backup scenarios. It is designed to run as a cron job and will log information to a text file (including remote file sizes, if you use Amazon S3 and have s3cmd installed).

Misc

Be sure to make the script executable if needed (chmod +x) before you hit the gas.

Upgrade

1. Get the new version

If you got the script by cloning the repository, upgrading is easy:

git pull

else just download again the ZIP archive an extract it over the existing folder. (Don't forget to keep a backup of the previous folder to be able to rollback easily if needed)

2. Adapt the config file if needed

Then compare the example config file (duplicity-backup.conf.example) with your modified version (for example /etc/duplicity-backup.conf) and adapt your copy to reflect the changes in the example file.

There are many ways to do so, here are some examples (adapt the path to your actual files):

diff duplicity-backup.conf.example /etc/duplicity-backup.conf
vimdiff duplicity-backup.conf.example /etc/duplicity-backup.conf

Dependencies

  • duplicity
  • Basic utilities like: bash, which, find and tee (should already be available on most Linux systems)
  • gpg optional (if using encryption)
  • mailx optional (if sending mail is activated in the script)

For the Amazon S3 storage backend optional

For the Backblaze B2 storage backend optional

For the Google Cloud Storage storage backend optional

  • boto (may already have been installed with duplicity)
  • gsutil optional

Usage

duplicity-backup.sh [options]

  Options:
    -c, --config CONFIG_FILE   specify the config file to use

    -b, --backup               runs an incremental backup
    -f, --full                 forces a full backup
    -v, --verify               verifies the backup
    -e, --cleanup              cleanup the backup (eg. broken sessions), by default using
                               duplicity --force flag, use --dry-run to actually log what
                               will be cleaned up without removing (see man duplicity
                               > ACTIONS > cleanup for details)
    -l, --list-current-files   lists the files currently backed up in the archive
    -s, --collection-status    show all the backup sets in the archive

        --restore [PATH]       restores the entire backup to [path]
        --restore-file [FILE_TO_RESTORE] [DESTINATION]
                               restore a specific file
        --restore-dir [DIR_TO_RESTORE] [DESTINATION]
                               restore a specific directory

    -t, --time TIME            specify the time from which to restore or list files
                               (see duplicity man page for the format)

    --backup-script            automatically backup the script and secret key(s) to
                               the current working directory

    -n, --dry-run              perform a trial run with no changes made
    -d, --debug                echo duplicity commands to logfile

    -V, --version              print version information about this script and duplicity

Usage Examples

View help:

duplicity-backup.sh

Run an incremental backup:

duplicity-backup.sh [-c config_file] --backup

Force a one-off full backup:

duplicity-backup.sh [-c config_file] --full

Restore your entire backup:

# You will be prompted for a restore directory
duplicity-backup.sh [-c config_file] --restore

# You can also provide a restore folder on the command line.
duplicity-backup.sh [-c config_file] --restore /home/user/restore-folder

Restore a specific file or directory in the backup:

Note that the commands --restore-file and --restore-dir are equivalent.

# You will be prompted for a file to restore to the current directory
duplicity-backup.sh [-c config_file] --restore-file

# Restores the file img/mom.jpg to the current directory
duplicity-backup.sh [-c config_file] --restore-file img/mom.jpg

# Restores the file img/mom.jpg to /home/user/i-love-mom.jpg
duplicity-backup.sh [-c config_file] --restore-file img/mom.jpg /home/user/i-love-mom.jpg

# Restores the directory rel/dir/path to /target/restorepath
duplicity-backup.sh [-c config_file] --restore-dir rel/dir/path /target/restorepath

List files in the remote archive

duplicity-backup.sh [-c config_file] --list-current-files

See the collection status (i.e. all the backup sets in the remote archive)

duplicity-backup.sh [-c config_file] --collection-status

Verify the backup

duplicity-backup.sh [-c config_file] --verify

Clean the backup

duplicity-backup.sh [-c config_file] --cleanup

Backup the script and gpg key in a encrypted tarfile (for safekeeping)

duplicity-backup.sh [-c config_file] --backup-script

Cron Usage Example (backup)

41 3 * * * /absolute/path/to/duplicity-backup.sh -c /etc/duplicity-backup.conf -b

Cron Usage Example (cleanup)

41 4 * * 1 /absolute/path/to/duplicity-backup.sh -c /etc/duplicity-backup.conf -e

Known issues

GPG error if system locale is not english

If your system's locale is not english, an error can happen when duplicity is trying to encrypt the files with gpg. This problem concerns duplicity and has been reported upstream (see bug report). A simple workaround is to set the following environement variable: LANG=C. For example: LANG=C duplicity-backup.sh [-c config_file] ... or in the cron 41 3 * * * LANG=C /absolute/path/to/duplicity-backup.sh -c /etc/duplicity-backup.conf -b

"/dev/fd/62: Operation not supported" errors on FreeBSD

See issue #143 for a fix.

Troubleshooting

This script attempts to simplify the task of running a duplicity command; if you are having any problems with the script the first step is to determine if the script is generating an incorrect command or if duplicity itself is causing your error.

To see exactly what is happening when you run duplicity-backup.sh, either pass the option -d or --debug on the command line, or head to the bottom of the configuration file and uncomment the ECHO=$(which echo) variable.

This will stop the script from running and will, instead, output the generated command into your log file. You can then check to see if what is being generated is causing an error or if it is duplicity causing you woe.

You can also try the -n or --dry-run option. This will make duplicity to calculate what would be done, but does not perform any backend actions. Together with info verbosity level (-v8) duplicity will list all files that will be affected. This way you will know exactly which files will be backed up or restored.

Wish List

  • Backup to multiple destinations with one config file
  • Show backup-ed files in today incremental backup email
Thanks to all the contributors for their help.

duplicity-backup.sh's People

Contributors

arichiardi avatar barofsoap avatar brki avatar colinfrei avatar csmithatsquiz avatar dgibbs64 avatar dismantl avatar dkolb avatar elisman avatar fergbrain avatar franek avatar gerardribas avatar gpini avatar harrim4n avatar ifdattic avatar intelligide avatar jbanety avatar jbernhard avatar jrbenito avatar lechup avatar marionline avatar mddirba avatar neal avatar phillxnet avatar piperj avatar rmarescu avatar sparanoid avatar thornomad avatar xmatthias avatar zertrin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

duplicity-backup.sh's Issues

Should I be concerned about this?

Import of duplicity.backends.sshbackend Failed: No module named paramiko
Import of duplicity.backends.giobackend Failed: No module named gio

(Sorry this should be a question not an issue, but I dont see where I set the label)

Permission denied issue

Hello,

Could someone explain to me why I get the Permission denied message when I try to run the script? I am running it as root and as far as I can see, root has all the required access to run the script.

Thanks and regards,

Pradeep

--restore-dir functionality

Implement possibility to restore a directory to a specific directory.
For example, restore /var/www to /tmp

Path of backup files

Hello

I don't know if it is a problem in my config or a script problem.
When I'm listing the file :

~/duplicity-backup# ./duplicity-backup.sh -c duplicity-backup.conf --list-current-files | grep default.cfg
Tue may 20 14:59:05 2014 home/martin/.willie/default.cfg

The path of the file start without the slash so when I do a restore I have to follow this rule.

./duplicity-backup.sh -c duplicity-backup.conf --restore-file home/martin/.willie/default.cfg /home/martin/.willierestore/

Is it normal?

Thanks in advance.

"Email couldn't be sent. 'sendmail' not available."

Hi there, it seems that duplicity-backup can't find sendmail on the server it's set up on. At the end of each duplicity-backup log I see:

---------    END DUPLICITY-BACKUP SCRIPT    ---------

Email couldn't be sent. 'sendmail' not available.
Removing lock. Exit code: 0

The backup script runs via a Cron job under user root, similar to the example in the docs:

30 23 * * * cd /path/to/duplicity-backup; ./duplicity-backup.sh -c /path/to/duplicity-backup.conf -b

Checking through the duplicity-backup.sh script I see the following:

MAILCMD=$(which $MAIL)
      if [ ! -x "$MAILCMD" ]; then
          echo -e "Email couldn't be sent. '${MAIL}' not available." >> ${LOGFILE}
      else

$MAIL is set to sendmail in the conf file:

MAIL="sendmail"

If I run which sendmail on a shelll as any user, including root, I see:

/usr/sbin/sendmail

I cobbled together a script test.sh like so:

#!/bin/bash
MAIL="sendmail"
MAILCMD=$(which $MAIL)

echo "MAIL is '${MAIL}'"
echo "MAILCMD is '${MAILCMD}'"

if [ ! -x "$MAILCMD" ]; then
        echo "Email can't be sent. '${MAIL}' not available."
else
        echo "Email can be sent. '${MAIL}' available."
fi

which, when run as a user and root both output:

$ ./test.sh
MAIL is 'sendmail'
MAILCMD is '/usr/sbin/sendmail'
Email can be sent. 'sendmail' available.

The only difference I see between my script and duplicity-backup.sh is the shebang line #!/usr/bin/env bash
I switched my script to that and the output still shows that sendmail is available.

Fairly puzzling as to why this would happen. If I try mailx then an error appears:

/usr/bin/mailx: invalid option -- 'r'

Which shows to me that a 'which mailx' is returning the path to mailx (i.e it's executing the 'else' part of the MAILCMD test).

I'll keep digging but if you have any ideas on this it would help greatly.
This is running on a Ubuntu 14.04 server.

Thanks
James

[Feature Request] Add option to allow non-interactive usage

I'm working on automating our duplicity solution using duplicity-backup, however the script is not non-interactive compliant at the moment. It would be great if there was an option to automatically answer yes to any questions and stop the script asking for user input.

Obviously needs some thought around how to do that for the encryption password - see my other issue!

Resume backup - encryption password required

Hi zertrin, I have been doing a fair bit of testing with duplicity-backup.

I've noticed that when a backup fails (eg. because of dropped connection - I'm backing up to s3), on the next run it will try to resume. On resume, it downloads the first volume of the backupset and tries to decrypt it.

At this point, I was getting the following error:

GPG error detail: Traceback (most recent call last):
File "/usr/bin/duplicity", line 1411, in
with_tempdir(main)
File "/usr/bin/duplicity", line 1404, in with_tempdir
fn()
File "/usr/bin/duplicity", line 1374, in main
full_backup(col_stats)
File "/usr/bin/duplicity", line 509, in full_backup
globals.backend)
File "/usr/bin/duplicity", line 346, in write_multivol
validate_encryption_settings(globals.restart.last_backup, mf)
File "/usr/bin/duplicity", line 334, in validate_encryption_settings
fileobj.close()
File "/usr/lib64/python2.6/site-packages/duplicity/dup_temp.py", line 225, in close
assert not self.fileobj.close()
File "/usr/lib64/python2.6/site-packages/duplicity/gpg.py", line 251, in close
self.gpg_failed()
File "/usr/lib64/python2.6/site-packages/duplicity/gpg.py", line 218, in gpg_failed
raise GPGError, msg
GPGError: GPG Failed, see log below:
===== Begin GnuPG log =====
gpg: encrypted with 2048-bit RSA key, ID 3C6E2351, created 2013-05-19 "Duplicity Backup Encryption Key for profiaa22 (Encryption key for Duplicity Backup for profiaa22) <securityteam@***>"
gpg: public key decryption failed: Bad passphrase
gpg: decryption failed: No secret key
can't connect to `/root/.gnupg/S.gpg-agent': No such file or directory ===== End GnuPG log =====

The key bit of this was "gpg: public key decryption failed: Bad passphrase". Since it is using the Encryption key to decrypt, and this key is not stored in the duplicity-backup config file, it doesn't seem surprising that it can't decrypt.

I've worked around this by 1). creating an ENC_PASSPHRASE variable in my duplicity-backup.conf file, eg:

PASSPHRASE="12345"
ENC_PASSPHRASE="1234"

and 2). modifying duplicity-backp.sh to export this as follows:

SIGN_PASSPHRASE=$PASSPHRASE
PASSPHRASE=$ENC_PASSPHRASE
export AWS_ACCESS_KEY_ID
export AWS_SECRET_ACCESS_KEY
export PASSPHRASE
export SIGN_PASSPHRASE

Clearly before the script was exporting the Signature passphrase as both PASSPHRASE & SIGN_PASSPHRASE - I'm not sure why this would be? Can you see any problems with what I've done? If not, then it would seem sensible to roll this into the production version...

Regards, Ben

[Feature Request] Backup to two different locations with only one .conf file

Hi,

Great script, thanks!

It would be nice to have the ability to have backups going to two different locations (probably different backends) in only one .conf file. I mean, backup to a local NAS and to Amazon S3 for local and offsite backup copies of same data. This is very easy to accomplish with two (or more) .conf files for the same data set, however it is more difficult to maintain and still need to call script twice for the backup. Would be interesting to manage from just one place (.conf) even do those two backup could be executed one after another sequentially by the script.

Please forgive if this is already possible but my lack of sleep avoid me from figuring out how :)

Thanks,
Benito

mail address fail

When using "mail" to send it sends to 4 recipients, $FROM $TO and -f@<my.domain.name> and --@<my.domain.name>

Somehow it's misunderstanding the -f and -- flags. I'm using mailx for now.

which: no s3cmd in...

Hi @zertrin,

I don't know if it is a bug or an OS depending thing, but when running the script without s3cmd installed I get:

which: no s3cmd in (/usr/lib64/qt-3.3/bin:/usr/NX/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/local/sbin:/usr/sbin:/home/jan/.local/bin:/home/jan/bin)

in the very first line of the output (the script is running anyway).
Even when the variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are commented out.

I didn't find a quick solution to suppress the warning :(

Some excluded directories still giving error in log

I used to have a problem with backing up /home because root didn't have permission to read ~/.gvfs, even though */.gvfs was in the excluded list. While this appears fixed in the (most recent) version I now use, I am facing the same problem again with ~/xrdp_client, again in the excluded list. As far as I can see, the backup completes regardless, but does still generate the log entry "Error accessing possibly locked file /home/user/xrdp_client".

If this isn't a simple fix, it would be useful to know which commit fixed the earlier problem with ignoring excluded files, so that I can try to understand what is happening.

Fix usage of mail command on Linux

When using MAIL="mail" on a Linux system (tested with Debian wheezy) the command parameters should be the same as for FreeBSD|Darwin|DragonFly|OpenBSD.
For instance, -f ${EMAIL_FROM} is not an option in Debian wheezy and results in an additional email send to -f@domain

Cannot send backup to amazon s3

Hello,

First, thanks for this excelent script. This works fine in my local network, but I can't send my backups to amazon s3.

I have installed and configured s3cm and my credentials are correct.

The error messages, after command, are:

Traceback (most recent call last):
File "/usr/bin/duplicity", line 1434, in
with_tempdir(main)
File "/usr/bin/duplicity", line 1428, in with_tempdir
fn()
File "/usr/bin/duplicity", line 1277, in main
do_backup(action)
File "/usr/bin/duplicity", line 1310, in do_backup
globals.archive_dir).set_values()
File "/usr/lib/python2.7/dist-packages/duplicity/collections.py", line 696, in set_values
self.get_backup_chains(partials + backend_filename_list)
File "/usr/lib/python2.7/dist-packages/duplicity/collections.py", line 819, in get_backup_chains
map(add_to_sets, filename_list)
File "/usr/lib/python2.7/dist-packages/duplicity/collections.py", line 813, in add_to_sets
log.Debug(_("File %s is not part of a known set; creating new set") % (filename,))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)

Could you help me?

Thanks
Marcelo

change lock file name?

bae default it is /var/log/duplicity-backup/backup.lock. Is it possible to change that? I'd like to run duplicity simultaneously.

/usr/bin/mailx: invalid option -- 'r'

Using the lasted revision on Debian wheezy I get the following error message:

## ./duplicity-backup.sh -c config
USAGE:
    duplicity-backup.sh [options]

  Options:
    -c, --config CONFIG_FILE   specify the config file to use

    -b, --backup               runs an incremental backup
    -f, --full                 forces a full backup
    -v, --verify               verifies the backup
    -l, --list-current-files   lists the files currently backed up in the archive
    -s, --collection-status    show all the backup sets in the archive

        --restore [PATH]       restores the entire backup to [path]
        --restore-file [FILE_TO_RESTORE] [DESTINATION]
                               restore a specific file
        --restore-dir [DIR_TO_RESTORE] [DESTINATION]
                               restore a specific directory

    -t, --time TIME            specify the time from which to restore or list files
                               (see duplicity man page for the format)

    --backup-script            automatically backup the script and secret key(s) to
                               the current working directory

    -n, --dry-run              perform a trial run with no changes made
    -d, --debug                echo duplicity commands to logfile

  CURRENT SCRIPT VARIABLES:
  ========================
    DEST (backup destination)       = XXXXX
    INCLIST (directories included)  = XXXXX
    EXCLIST (directories excluded)  = 
    ROOT (root directory of backup) = /
    LOGFILE (log file path)         = /root/new_backup/duplicity-2015-01-20_13-26.txt


/usr/bin/mailx: invalid option -- 'r'
usage: mailx [-dEIinv] [-a header] [-b bcc-addr] [-c cc-addr] [-s subject] to-addr ...
       mailx [-dEIiNnv] -f [name]
       mailx [-dEIiNnv] [-u user]

When I change MAIL to "mail" everything works fine.

Restarting after volume

Hello

I know it's not related to duplicity-backup but more to duplicity itself but when I try to do a backup I always get stuck
Restarting after volume 10, file opt/vc/src/hello_pi/hello_video/test.h264, block 13

If someone have an idea?

Thanks in advance

du --exclude-from problem

Im running this script on freebsd, however, in freebsd du doesn't support --exclude-from.
The script gives an error:
du: illegal option -- -
usage: du [-Aclnx] [-H | -L | -P] [-h | -k | -m ] [-a | -s | -d depth] [-B blocksize] [-I mask] [-t threshold] [file ...]

hoping for a fix.

-s (collection-status) option not writing anythign to log file

I have two .conf files set up to run via cron writing to two log files. The first one is a daily backup which write all output to the log and emails me via ssmtp. I know email is working.

When I run the second job which uses a copy of the daily backup conf file just modified to run -s instead of -b and writing to a different log file I get no proper output int the log:

-------- START DUPLICITY-BACKUP SCRIPT --------

Attempting to acquire lock /var/log/backup.lock
successfully acquired lock.
-------- END --------

-------- END DUPLICITY-BACKUP SCRIPT --------

I'll fork the code and see if I can fix.

unable to backup

/usr/local/bin/duplicity-backup.sh -c /etc/duplicity-backup.conf -f
/usr/local/bin/duplicity-backup.sh: eval: line 490: unexpected EOF while looking for matching `''
/usr/local/bin/duplicity-backup.sh: eval: line 491: syntax error: unexpected end of file

restore option does not write to logfile

From line 578 - just needs to be piped to tee again:

echo "Restoring now ..."
#use INCLUDE variable without create another one
INCLUDE="--file-to-restore ${FILE_TO_RESTORE}"
duplicity_backup  | tee -a ${LOGFILE}
;;

Also - is there an option to choose from what set within a backup to restore from ? What if I wanted to restore a file from last month ? Cheers

Backup fails with code 0 and empty logs

My backups have been failing silently (returning a code 0, which should mean success). My monitoring scripts have failed to alert me (because of the code 0), and I didn't get any email (probably because I don't have mailx, mail, or ssmtp). In the logs it says "Current Remote Backup File Size: s3cmd not installed.". I have s3cmd installed, so that's not the issue.

I see three issues here:

  1. Backups should never fail with a code 0.
  2. The "s3cmd not installed" message is wrong, or at least not very helpful in debugging the real issue.
  3. The default mail command setting should be something that is typically installed by default (e.g. sendmail).

syntax error on line 200

I get this error when running the script

/usr/local/bin/duplicity-backup.sh: line 200: unexpected token `newline', conditional binary operator expected
/usr/local/bin/duplicity-backup.sh: line 200: syntax error near `\'
/usr/local/bin/duplicity-backup.sh: line 200: `         ${GPG_SIGN_KEY} = "foobar_gpg_key" || \         '

There's extra whitespace after the line.

Mail command fails on Centos 5.5 i686 (patch)

On Centos 5.5 i686, even with the mailx package installed from yum, the script still won't send via mailx (which isn't in the PATH, or even an installed file (?)) I'm not a big Centos user, so I fixed the script so that it will also send with the stock mail command, this requires two patches:

diff --git a/duplicity-backup.conf.example b/duplicity-backup.conf.example
index 89861be..5037292 100644
--- a/duplicity-backup.conf.example
+++ b/duplicity-backup.conf.example
@@ -160,6 +160,7 @@ EMAIL_SUBJECT=
 
 # command to use to send mail
 MAIL="mailx"
+#MAIL="mail"
 #MAIL="ssmtp"
 
 # TROUBLESHOOTING: If you are having any problems running this script it is



diff --git a/duplicity-backup.sh b/duplicity-backup.sh
index c3fc583..68c5f35 100755
--- a/duplicity-backup.sh
+++ b/duplicity-backup.sh
@@ -241,6 +241,8 @@ email_logfile()
           elif [ "$MAIL" = "mailx" ]; then
             EMAIL_FROM=${EMAIL_FROM:+"-r ${EMAIL_FROM}"}
             cat ${LOGFILE} | ${MAILCMD} -s """${EMAIL_SUBJECT}""" $EMAIL_FROM ${EMAIL_TO}
+          elif [ "$MAIL" = "mail" ]; then
+            cat ${LOGFILE} | ${MAILCMD} -s """${EMAIL_SUBJECT}""" $EMAIL_FROM ${EMAIL_TO} -- -f ${EMAIL_FROM}
           fi
           echo -e "Email alert sent to ${EMAIL_TO} using ${MAIL}" >> ${LOGFILE}
       fi

Import of duplicity.backends.giobackend

I'll get this error when running the script.

Import of duplicity.backends.giobackend Failed: No module named gio

I'll use

  • duplicity 0.6.18
  • s3cmd version 1.0.0
  • gpg (GnuPG) 1.4.11
  • Ubuntu 12.04.4 LTS (GNU/Linux 3.2.0-60-virtual x86_64)

Running the "naked" duplicity command throws


Import of duplicity.backends.giobackend Failed: No module named gio
Traceback (most recent call last):
  File "/usr/bin/duplicity", line 1414, in <module>
    with_tempdir(main)
  File "/usr/bin/duplicity", line 1407, in with_tempdir
    fn()
  File "/usr/bin/duplicity", line 1258, in main
    action = commandline.ProcessCommandLine(sys.argv[1:])
  File "/usr/lib/python2.7/dist-packages/duplicity/commandline.py", line 1007, in ProcessCommandLine
    backup, local_pathname = set_backend(args[0], args[1])
  File "/usr/lib/python2.7/dist-packages/duplicity/commandline.py", line 900, in set_backend
    globals.backend = backend.get_backend(bend)
  File "/usr/lib/python2.7/dist-packages/duplicity/backend.py", line 158, in get_backend
    return _backends[pu.scheme](pu)
  File "/usr/lib/python2.7/dist-packages/duplicity/backends/_boto_single.py", line 77, in __init__
    self.resetConnection()
  File "/usr/lib/python2.7/dist-packages/duplicity/backends/_boto_single.py", line 144, in resetConnection
    self.conn = S3Connection(is_secure=(not globals.s3_unencrypted_connection))
  File "/usr/lib/python2.7/dist-packages/boto/s3/connection.py", line 154, in __init__
    suppress_consec_slashes=suppress_consec_slashes)
  File "/usr/lib/python2.7/dist-packages/boto/connection.py", line 486, in __init__
    host, config, self.provider, self._required_auth_capability())
  File "/usr/lib/python2.7/dist-packages/boto/auth.py", line 406, in get_auth_handler
    'Check your credentials' % (len(names), str(names)))
NoAuthHandlerFound: No handler was ready to authenticate. 1 handlers were checked. ['HmacAuthV1Handler'] Check your credentials

What am I missing?

Here my configuration file:

#!/bin/bash

# AMAZON S3 INFORMATION
# Comment out these lines if you're not using Amazon S3
AWS_ACCESS_KEY_ID="asdf"
AWS_SECRET_ACCESS_KEY="asdf"

# S3CMD INFORMATION
# Most people don't need this, but in some cases
# you may want to specify a custom configuration file
# to pass to s3cmd. If so, set the S3CMD_CONF_FILE variable
# to the full path of this custom config file.
# Per default s3cmd uses ${HOME}/.s3cfg
# S3CMD_CONF_FILE='/path/to/your/s3cmd/conf/file'

ENCRYPTION='yes'

PASSPHRASE="asdf"

GPG_ENC_KEY="asdf"
GPG_SIGN_KEY="asdf"

ROOT="/var"

# BACKUP DESTINATION INFORMATION
# The s3+http scheme uses the default aws s3 hostname.
# Use s3://host/bucket/[backup-folder/] if you want to specify the host name.
# If using the s3://... scheme and you have s3cmd installed, be sure to change
# 's3.amazonaws.com' to the appropriate host in your .s3cfg file so that the
# remote file size check will work.
#DEST="s3://host/backup-bucket/backup-folder/"
DEST="s3+http://asdf/asdf/"

INCLIST=(  "/var/backup/db" \
           "/var/www/wordpress/wp-content" \
        )

STATIC_OPTIONS="--full-if-older-than 14D --s3-use-new-style  --s3-european-buckets"

CLEAN_UP_TYPE="remove-all-but-n-full"
CLEAN_UP_VARIABLE="4"

LOGDIR="/var/log/duplicity-backup/"
LOG_FILE="duplicity-`date +%Y-%m-%d_%H-%M`.txt"
LOG_FILE_OWNER="root:ubuntu"
VERBOSITY="-v3"

EMAIL_TO=
EMAIL_FROM=
EMAIL_SUBJECT=

MAIL="mailx"     # default command for Linux mail

Amazon: Command not found

Slight change needed here on testing $FRIEND_NAME for the size check;

if $FRIENDLY_TYPE_NAME ; then

.. to ..

if [[ $FRIENDLY_TYPE_NAME ]] ; then

"No such file or directory" - error when running current script

Hi there, I updated my copy of duplicity-backup.sh to the current version last week. Since then, duplicity has not been running - I went to check it today manually, and when I call duplicity-backup.sh (with or without parameters), I receive the error "No such file or directory". I do not know which file or directory it is referring to which is missing. I always supply the full path to the config file when I run duplicity via cron using the -c switch, I have checked the cron line and it is supplying the correct path and the file exists. However, the same error is returned whether or not -c is specified.

Could you update the script to inform the user which file or directory it is looking for which is missing?

AHA, Ben

how to force a full restoration in "/"

Hello,

in case of a full backup for a virtual machine, how can I force a full restoration in / path ?

Thanks for your scripts they are very good for simply use duplicity.

Sincerely
Guidtz

Multiple recipients.

First, great job on the script it's wonderful and saved me heaps of time.

Not really an issue but didnt warrant a merge request. I noticed if you try to include multiple email recipients in the EMAIL_TO="" as so:

EMAIL_TO="[email protected] [email protected]"

The script returns the error "unary operator expected"

If you make a quick change to your bash syntax in duplicity-backup.sh at line 249 this is no longer a problem.

[$EMAIL_TO] becomes ["$EMAIL_TO"]

Hopefully that helps out someone else, Thanks for sharing the great work!

Running a cron job

Hello there,

This is not an issue. Just a question but I'm not sure how to mark this as a question.

I have installed your script and everything is running so smoothly now so the next step would be automating it. I entered the following two lines to the crontab file inside /etc folder but nothing seems to be happening.

0 4 * * * 1-6 root /root/duplicity-backup.sh -c /etc/duplicity-backup.conf --backup
0 4 * * * 7 root /root/duplicity-backup.sh -c /etc/duplicity-backup.conf --full

Could you explain what I'm doing wrong in here? Is it because the crontab file inside the /etc folder can't run this as root? If it is the case, how can I overcome that issue?

Thanks and regards,

Pradeep

Duplicity backup to Google Docs now results in 404 error

When running duplicity.sh -b, I know get a 404 error saying:

ClientLoginFailed: Server responded to ClientLogin request: 404, https://developers.google.com/accounts/docs/AuthForInstalledApps

I believe it may be because Google OAuth1 is now officially deprecated? I'm not quite sure. Some new form of authentication may be required, or it's totally on my end. Here's the whole output I get when I Run duplicity:

Traceback (most recent call last):
  File "/usr/bin/duplicity", line 1523, in <module>
    with_tempdir(main)
  File "/usr/bin/duplicity", line 1517, in with_tempdir
    fn()
  File "/usr/bin/duplicity", line 1355, in main
    action = commandline.ProcessCommandLine(sys.argv[1:])
  File "/usr/lib/python2.7/site-packages/duplicity/commandline.py", line 1101, in ProcessCommandLine
    backup, local_pathname = set_backend(args[0], args[1])
  File "/usr/lib/python2.7/site-packages/duplicity/commandline.py", line 992, in set_backend
    globals.backend = backend.get_backend(bend)
  File "/usr/lib/python2.7/site-packages/duplicity/backend.py", line 223, in get_backend
    obj = get_backend_object(url_string)
  File "/usr/lib/python2.7/site-packages/duplicity/backend.py", line 209, in get_backend_object
    return factory(pu)
  File "/usr/lib/python2.7/site-packages/duplicity/backends/gdocsbackend.py", line 54, in __init__
    self._authorize(parsed_url.username + '@' + parsed_url.hostname, self.get_password())
  File "/usr/lib/python2.7/site-packages/duplicity/backends/gdocsbackend.py", line 134, in _authorize
    captcha_response=captcha_response)
  File "/usr/lib/python2.7/site-packages/gdata/client.py", line 441, in client_login
    captcha_token=captcha_token, captcha_response=captcha_response)  
  File "/usr/lib/python2.7/site-packages/gdata/client.py", line 373, in request_client_login_token
    response, ClientLoginFailed, response_body)
ClientLoginFailed: Server responded to ClientLogin request: 404,        https://developers.google.com/accounts/docs/AuthForInstalledApps


Traceback (most recent call last):
  File "/usr/bin/duplicity", line 1523, in <module>
    with_tempdir(main)
  File "/usr/bin/duplicity", line 1517, in with_tempdir
    fn()
  File "/usr/bin/duplicity", line 1355, in main
    action = commandline.ProcessCommandLine(sys.argv[1:])
  File "/usr/lib/python2.7/site-packages/duplicity/commandline.py", line 1093, in  ProcessCommandLine
    globals.backend = backend.get_backend(args[0])
  File "/usr/lib/python2.7/site-packages/duplicity/backend.py", line 223, in get_backend
    obj = get_backend_object(url_string)
  File "/usr/lib/python2.7/site-packages/duplicity/backend.py", line 209, in get_backend_object
    return factory(pu)
  File "/usr/lib/python2.7/site-packages/duplicity/backends/gdocsbackend.py", line 54, in __init__
    self._authorize(parsed_url.username + '@' + parsed_url.hostname, self.get_password())
  File "/usr/lib/python2.7/site-packages/duplicity/backends/gdocsbackend.py", line 134, in _authorize
    captcha_response=captcha_response)
  File "/usr/lib/python2.7/site-packages/gdata/client.py", line 441, in client_login
    captcha_token=captcha_token, captcha_response=captcha_response)
  File "/usr/lib/python2.7/site-packages/gdata/client.py", line 373, in request_client_login_token
    response, ClientLoginFailed, response_body)
ClientLoginFailed: Server responded to ClientLogin request: 404,     https://developers.google.com/accounts/docs/AuthForInstalledApps

Thank you!

Which happens if I add to INCLIST some time between full backups?

Thanks for this and to Damon. I have it working nicely on my VPS at Linode.

I have a quick question.

What happens if I add more to INCLIST now that I have it running? I'm using the default --full-if-older-than 14D option. The new directories won't be included in the last full backup. Do I need to force a full backup after adding to INCLIST or does it somehow take care of this?

Unwanted dirs showing up failing in output

I have the ROOT set up as "/"

and the INCLIST set up as:

INCLIST=( "/etc/nginx"
"/etc/php5"
"/home/ilium007"
"/apps"
)

When the backup runs I see these errors:

Last full backup date: Sun Aug 18 15:26:54 2013
Error accessing possibly locked file /etc/.pwd.lock
Error accessing possibly locked file /etc/at.deny
Error accessing possibly locked file /etc/fuse.conf
Error accessing possibly locked file /etc/group-
Error accessing possibly locked file /etc/gshadow
Error accessing possibly locked file /etc/gshadow-
Error accessing possibly locked file /etc/passwd-
Error accessing possibly locked file /etc/shadow
Error accessing possibly locked file /etc/shadow-
Error accessing possibly locked file /etc/sudoers
Error accessing possibly locked file /lost+found
Error accessing possibly locked file /root
Error accessing possibly locked file /swapfile

I have asked for none of these files to be backed up yet there are 13 errors.

Feature/Enhancement: Option for separate backup sets

Hi @zertrin,

just a little idea:

How about an option to create separate backup sets for each folder defined in "INCLIST"?

Before I used this script, I created a little script by myself which created seperate backups sets for each folder I wanted to backup at a "global" destination.

For example:

Backup folders:
/home/foo
/home/bar
/home/foobar

Backup destination:
scp://user@host/duplicity_backup_folder/home_foo/
scp://user@host/duplicity_backup_folder/home_bar/
scp://user@host/duplicity_backup_folder/home_foobar/

So the backups are independent.
IMHO the advantages of using separate backup sets are:

  • You don't have to download the complete duplicity archives for folders you don't want to restore (just think of Amazons traffic fees for outgoing traffic if you are using S3 as destination)
  • If a backup set, for whatever reasons, gets corrupted then just one folder is affected - not the complete backup

What do you think?

Greetz
puredoze

Always get "TEST RUN ONLY: Check the logfile for command output"

I'm baffled by what I'm doing wrong, as when I run for example

./duplicity-backup.sh --config duplicity-backup.conf --backup

I see the log output like:

-------- START DUPLICITY-BACKUP SCRIPT --------

Attempting to acquire lock /home/keithzg/workspace/test_offsite/logs/backup.lock
successfully acquired lock.
/usr/bin/duplicity -v3 --full-if-older-than 14D --s3-use-new-style --no-encryption --exclude /home/keithzg/workspace/test_offsite/logs --include=/home/keithzg/workspace/test_offsite --exclude=** /home/keithzg/workspace/ s3+http://keithzg_test1/
-----------[ Duplicity Cleanup ]-----------
/usr/bin/duplicity remove-all-but-n-full 2 --full-if-older-than 14D --s3-use-new-style --force --no-encryption s3+http://keithzg_test1/

---------[ Source File Size Information ]---------
110M /home/keithzg/workspace/test_offsite

------[ Destination File Size Information ]------
Current Remote Backup File Size: 388M

-------- END DUPLICITY-BACKUP SCRIPT --------

Removing lock. Exit code: 0

If I try and run the commands listed in the log file manually, it works fine. So why is it assuming I want to just do a test run when I'm running the script itself?

Restore error if no target name

First I must say, great script. I had to look through the entire internet and was almost ready to pay someone to create sync to S3 for me.

I have gotten everything to backup to S3 which is nice.

But I am having trouble restoring. I have tried multiple commands. First I want to test to restore one file.

Here is an example:

./duplicity-backup.sh --restore-file /home/httpd/backups/dbdump_2012-04-03_13-00-52.tar.bz2

I get this:
Restoring now ...
../duplicity-backup.sh: eval: line 366: unexpected EOF while looking for matching `''
../duplicity-backup.sh: eval: line 367: syntax error: unexpected end of file

I try this:

./duplicity-backup.sh --restore-file dbdump_2012-04-03_13-00-52.tar.bz2

I get this:

Restoring now ...
Traceback (most recent call last):
File "/usr/bin/duplicity", line 1251, in
with_tempdir(main)
File "/usr/bin/duplicity", line 1244, in with_tempdir
fn()
File "/usr/bin/duplicity", line 1198, in main
restore(col_stats)
File "/usr/bin/duplicity", line 538, in restore
restore_get_patched_rop_iter(col_stats)):
File "/usr/bin/duplicity", line 560, in restore_get_patched_rop_iter
backup_chain = col_stats.get_backup_chain_at_time(time)
File "/usr/lib/python2.6/dist-packages/duplicity/collections.py", line 934, in get_backup_chain_at_time
raise CollectionsError("No backup chains found")
CollectionsError: No backup chains found

I have not tested the full restore yet, since the backup is 5GB.

I don't run as root, if that is required?

Thanks.

STATIC_OPTIONS appears non-functional

If I run ./duplicity-backup.sh with no options set at CLI, only STATIC_OPTIONS="--full-if-older-than 7D" in .conf, script exits. If I set --full-if-older-than 7D at CLI, script exits.

It looks like the script isn't passing $STATIC_OPTIONS to duplicity, that the variable isn't actually set in the script.

It is more elegant to be able to set static options in .conf, allowing use of only one cron entry to handle incremental and full backups, so this would be an excellent feature to complete.

Great work on the script. Thanks.

Handle --time option for restoration

Ehancement idea from a comment on Damon Timm's blog:

June 10, 2012 at 11:38 am
Lou says:
Is there anyway specify the duplicity time variable in a restore a specific backup?
Something like the man page give here:

duplicity [restore] [options] [--file-to-restore ] [--time time] source_url target_directory

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.