Commit ab86bd64 authored by bescoto's avatar bescoto

Remove older than overenthusiastic deletion fix


git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup@689 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
parent 646dcef8
......@@ -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)
--------------------------
......
......@@ -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))
......
......@@ -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"""
......
......@@ -16,6 +16,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.1.2 (2005/11/06)
--------------------------
......
Make sure remove older than doesn't delete current snapshot. When no
increments found, don't act like there's an error (no stderr).
Port close file fix to devel version
See if rorpiter.CacheIndexable is really necessary
For comparing, check source filesystem's abilities
Clean up compare reports
......
......@@ -37,9 +37,9 @@ blocksize = 131072
# values may save on connection overhead and latency.
conn_bufsize = 393216
# This is used in rorpiter.CacheIndexable. The number represents the
# number of rpaths which may be stuck in buffers when moving over a
# remote connection.
# This is used in the CacheCollatedPostProcess and MiscIterToFile
# classes. The number represents the number of rpaths which may be
# stuck in buffers when moving over a remote connection.
pipeline_max_length = 500
# True if script is running as a server
......
......@@ -658,17 +658,24 @@ def RemoveOlderThan(rootrp):
"""Remove all increment files older than a certain time"""
rootrp = require_root_set(rootrp, 0)
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))
......@@ -676,11 +683,10 @@ 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"""
......
......@@ -427,13 +427,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"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment