summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2005-11-24 05:07:09 +0000
committerbescoto <bescoto@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109>2005-11-24 05:07:09 +0000
commitda3cdf9df0177e72f0b89246eff7e17ff58e4477 (patch)
treed4d4b89000ba82b66a58f9821060b65690e32aa6
parent559b413a54f2e6c33347f9f1dc97b8c84880eb1d (diff)
downloadrdiff-backup-da3cdf9df0177e72f0b89246eff7e17ff58e4477.tar.gz
Remove older than overenthusiastic deletion fix
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/branches/r1-0@689 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
-rw-r--r--rdiff-backup/CHANGELOG4
-rw-r--r--rdiff-backup/rdiff_backup/Main.py24
-rw-r--r--rdiff-backup/testing/finaltest.py27
3 files changed, 43 insertions, 12 deletions
diff --git a/rdiff-backup/CHANGELOG b/rdiff-backup/CHANGELOG
index 3d8d6e7..239f5f2 100644
--- a/rdiff-backup/CHANGELOG
+++ b/rdiff-backup/CHANGELOG
@@ -11,6 +11,10 @@ Due to very detailed error report from Yoav, fixed a "Directory not
empty" error that can arise on emulated filesystems like NFS and
EncFS.
+Cleaned up remove older than report, and also stopped it from deleting
+current data files if you specify a time later than the current
+mirror.
+
New in v1.0.2 (2005/10/24)
--------------------------
diff --git a/rdiff-backup/rdiff_backup/Main.py b/rdiff-backup/rdiff_backup/Main.py
index 1b46d1e..fc3142c 100644
--- a/rdiff-backup/rdiff_backup/Main.py
+++ b/rdiff-backup/rdiff_backup/Main.py
@@ -757,17 +757,24 @@ def RemoveOlderThan(rootrp):
"""Remove all increment files older than a certain time"""
rootrp = require_root_set(rootrp)
rot_require_rbdir_base(rootrp)
- try: time = Time.genstrtotime(remove_older_than_string)
+
+ time = rot_check_time(remove_older_than_string)
+ if time is None: return
+ Log("Actual remove older than time: %s" % (time,), 6)
+ manage.delete_earlier_than(Globals.rbdir, time)
+
+def rot_check_time(time_string):
+ """Check remove older than time_string, return time in seconds"""
+ try: time = Time.genstrtotime(time_string)
except Time.TimeException, exc: Log.FatalError(str(exc))
- timep = Time.timetopretty(time)
- Log("Deleting increment(s) before %s" % timep, 4)
times_in_secs = [inc.getinctime() for inc in
restore.get_inclist(Globals.rbdir.append_path("increments"))]
times_in_secs = filter(lambda t: t < time, times_in_secs)
if not times_in_secs:
- Log.FatalError("No increments older than %s found, exiting."
- % (timep,), 1, errlevel = 0)
+ Log("No increments older than %s found, exiting." %
+ (Time.timetopretty(time),), 3)
+ return None
times_in_secs.sort()
inc_pretty_time = "\n".join(map(Time.timetopretty, times_in_secs))
@@ -775,17 +782,16 @@ def RemoveOlderThan(rootrp):
Log.FatalError("Found %d relevant increments, dated:\n%s"
"\nIf you want to delete multiple increments in this way, "
"use the --force." % (len(times_in_secs), inc_pretty_time))
-
if len(times_in_secs) == 1:
Log("Deleting increment at time:\n" + inc_pretty_time, 3)
else: Log("Deleting increments at times:\n" + inc_pretty_time, 3)
- manage.delete_earlier_than(Globals.rbdir, time)
+ return times_in_secs[-1]+1 # make sure we don't delete current increment
def rot_require_rbdir_base(rootrp):
"""Make sure pointing to base of rdiff-backup dir"""
if restore_index != ():
- Log.FatalError("Increments for directory %s cannot be removed separately.\n"
- "Instead run on entire directory %s." %
+ Log.FatalError("Increments for directory %s cannot be removed "
+ "separately.\nInstead run on entire directory %s." %
(rootrp.path, restore_root.path))
diff --git a/rdiff-backup/testing/finaltest.py b/rdiff-backup/testing/finaltest.py
index 65f38e5..8acfee6 100644
--- a/rdiff-backup/testing/finaltest.py
+++ b/rdiff-backup/testing/finaltest.py
@@ -425,13 +425,34 @@ class FinalMisc(PathSetter):
for inc in self.get_all_increments(rbdir):
assert inc.getinctime() >= 30000
+ def testRemoveOlderThanCurrent(self):
+ """Make sure --remove-older-than doesn't delete current incs"""
+ Myrm("testfiles/output")
+ assert not os.system('cp -a testfiles/restoretest3 testfiles/output')
+ self.set_connections(None, None, None, None)
+ self.exec_rb_extra_args(None, '--remove-older-than now --force',
+ 'testfiles/output')
+ rbdir = rpath.RPath(Globals.local_connection,
+ "testfiles/output/rdiff-backup-data")
+
+ has_cur_mirror, has_metadata = 0, 0
+ for inc in self.get_all_increments(rbdir):
+ if inc.getincbase().index[-1] == 'current_mirror':
+ has_cur_mirror = 1
+ elif inc.getincbase().index[-1] == 'mirror_metadata':
+ has_metadata = 1
+ assert has_cur_mirror and has_metadata, (has_cur_mirror, has_metadata)
+
def testRemoveOlderThanQuoting(self):
"""Test --remove-older-than when dest directory is quoted"""
Myrm("testfiles/output")
self.set_connections(None, None, None, None)
- self.exec_rb_extra_args(None, "--override-chars-to-quote '^a-z0-9_ -.'",
- "testfiles/increment1", "testfiles/output")
- self.exec_rb_extra_args(None, "--remove-older-than now", "testfiles/output")
+ self.exec_rb_extra_args(None, "--override-chars-to-quote '^a-z0-9_ -.'"
+ " --current-time 10000", "testfiles/increment1", "testfiles/output")
+ self.exec_rb_extra_args(None, "--override-chars-to-quote '^a-z0-9_ -.'"
+ " --current-time 20000", "testfiles/increment2", "testfiles/output")
+ self.exec_rb_extra_args(None, "--remove-older-than now",
+ "testfiles/output")
def testRemoveOlderThanRemote(self):
"""Test --remove-older-than remotely"""