Merge lp:~angusgr/duplicity/exclude-older-than into lp:~duplicity-team/duplicity/0.7-series

Proposed by Angus Gratton
Status: Merged
Merged at revision: 1065
Proposed branch: lp:~angusgr/duplicity/exclude-older-than
Merge into: lp:~duplicity-team/duplicity/0.7-series
Diff against target: 72 lines (+33/-0)
3 files modified
bin/duplicity.1 (+9/-0)
duplicity/commandline.py (+4/-0)
duplicity/selection.py (+20/-0)
To merge this branch: bzr merge lp:~angusgr/duplicity/exclude-older-than
Reviewer Review Type Date Requested Status
duplicity-team Pending
Review via email: mp+247922@code.launchpad.net

Description of the change

Hi,

I have a small change that I've been using for over a year now for my own backups, and I realised I should probably submit it back. I'm not sure if you'll want to include it, but it's been useful for me.

The change is an "--exclude-older-than" command line option, that allows you to only back up files with a modification date newer than a particular threshold.

How I personally use it is for my off-site backups. Every couple of months I swap a physical hard disk off-site which contains a full disk backup via duplicity. However every hour or so I run an incremental backup to S3 covering my most used directories. The S3 backup has the option --exclude-older-than 90D passed to it.

Provided I rotate the "large" off-site backup more regularly than every 90 days, I can expect that between the two backups I have a complete set of the data that matters to me. If I backuped everything up to S3 then it'd be expensive and clog up my poor low-bandwidth upstream ADSL link, but a lot of it is data that hasn't changed in months.

I don't know if this kind of configuration will work for anyone apart from just me, but I thought you might find the option interesting anyhow.

Thanks very much for duplicity btw, it's a great tool that has saved me several times now!

Angus

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/duplicity.1'
2--- bin/duplicity.1 2015-01-26 16:08:57 +0000
3+++ bin/duplicity.1 2015-01-29 01:01:26 +0000
4@@ -510,6 +510,15 @@
5 come before any other include or exclude options.
6
7 .TP
8+.BR "--exclude-older-than " time
9+Exclude any files whose modification date is earlier than the specified
10+.IR time .
11+This can be used to produce a partial backup that contains only
12+recently changed files. See the
13+.B TIME FORMATS
14+section for more information.
15+
16+.TP
17 .BI --exclude-other-filesystems
18 Exclude files on file systems (identified by device number) other than
19 the file system the root of the source directory is on.
20
21=== modified file 'duplicity/commandline.py'
22--- duplicity/commandline.py 2015-01-26 16:08:57 +0000
23+++ duplicity/commandline.py 2015-01-29 01:01:26 +0000
24@@ -316,6 +316,10 @@
25 parser.add_option("--exclude-regexp", metavar=_("regular_expression"),
26 dest="", type="string", action="callback", callback=add_selection)
27
28+ # Exclude any files with modification dates older than this from the backup
29+ parser.add_option("--exclude-older-than", type="time", metavar=_("time"),
30+ dest="", action="callback", callback=add_selection)
31+
32 # Whether we should be particularly aggressive when cleaning up
33 parser.add_option("--extra-clean", action="store_true")
34
35
36=== modified file 'duplicity/selection.py'
37--- duplicity/selection.py 2015-01-22 20:04:16 +0000
38+++ duplicity/selection.py 2015-01-29 01:01:26 +0000
39@@ -245,6 +245,8 @@
40 self.add_selection_func(self.other_filesystems_get_sf(0))
41 elif opt == "--exclude-regexp":
42 self.add_selection_func(self.regexp_get_sf(arg, 0))
43+ elif opt == "--exclude-older-than":
44+ self.add_selection_func(self.exclude_older_get_sf(arg))
45 elif opt == "--include":
46 self.add_selection_func(self.glob_get_sf(arg, 1))
47 elif opt == "--include-filelist":
48@@ -644,6 +646,24 @@
49 else:
50 return exclude_sel_func
51
52+ def exclude_older_get_sf(self, date):
53+ """Return selection function based on files older than modification date """
54+
55+ def sel_func(path):
56+ if not path.isreg():
57+ return None
58+ try:
59+ if os.path.getmtime(path.name) < date:
60+ return 0
61+ except OSError, e:
62+ pass # this is probably only on a race condition of file being deleted
63+ return None
64+
65+ sel_func.exclude = True
66+ sel_func.name = "Select older than %s" % (date,)
67+ return sel_func
68+
69+
70 def glob_get_prefix_res(self, glob_str):
71 """Return list of regexps equivalent to prefixes of glob_str"""
72 glob_parts = glob_str.split("/")

Subscribers

People subscribed via source and target branches