Discussion:
[Erp5-dev] [Erp5-report] r28022 - /erp5/trunk/products/TIDStorage/repozo/
Julien Muchembled
2009-07-08 12:28:10 UTC
Permalink
Add --cleanup command to repozo_tidstorage in order to remove OLD backups safely.
Julien
Author: jm
Date: Wed Jul 8 13:47:02 2009
New Revision: 28022
URL: http://svn.erp5.org?rev=28022&view=rev
Add --cleanup command to repozo_tidstorage in order to remove all backups safely.
erp5/trunk/products/TIDStorage/repozo/repozo_tidstorage.py
erp5/trunk/products/TIDStorage/repozo/sample_configuration.py
Modified: erp5/trunk/products/TIDStorage/repozo/repozo_tidstorage.py
URL: http://svn.erp5.org/erp5/trunk/products/TIDStorage/repozo/repozo_tidstorage.py?rev=28022&r1=28021&r2=28022&view=diff
==============================================================================
--- erp5/trunk/products/TIDStorage/repozo/repozo_tidstorage.py [utf8] (original)
+++ erp5/trunk/products/TIDStorage/repozo/repozo_tidstorage.py [utf8] Wed Jul 8 13:47:02 2009
@@ -55,6 +55,7 @@
import imp
import getopt
+import glob
import sys
import os
import md5
@@ -62,12 +63,45 @@
import tempfile
from shutil import copy
-from repozo.restore_tidstorage import parse, get_tid_position
+from restore_tidstorage import parse, get_tid_position
program = sys.argv[0]
print message
+
+def cleanup(known_tid_storage_identifier_dict, keep_full_backup_count,
+ raise ValueError("A number of full backups to keep must be specified.")
+ cleanup_list = []
+ date_len = 19
+ oldest_fsz = None # Oldest full backup to keep among all storages.
+ for file_path, storage_path, object_path \
+ # Find oldest full backup to keep for this storage -> fsz
+ fsz_list = sorted(glob.glob(os.path.join(storage_path, '*.fsz')))
+ fsz = fsz_list[max(0, len(fsz_list) - keep_full_backup_count)]
+ fsz, ext = os.path.splitext(os.path.basename(fsz))
+ assert len(fsz) == date_len
+ oldest_fsz = fsz
+ # Clean up all repozo files older than fsz.
+ date, ext = os.path.splitext(os.path.basename(path))
+ assert len(date) == date_len
+ cleanup_list.append(path)
+ # Clean up all status files older than oldest_fsz.
+ prefix = os.path.join(status_file_backup_dir,
+ os.path.basename(status_file) + '-')
+ path_len = len(prefix) + date_len
+ assert path.startswith(path) and len(path) == path_len
+ cleanup_list.append(path)
+ return cleanup_list
"""Backups all ZODB files"""
@@ -193,7 +227,7 @@
['help', 'verbose', 'quick', 'full',
'gzip', 'repository', 'repozo=',
'config=','recover', 'recover_check',
- 'tid_log='])
+ 'tid_log=', 'cleanup'])
usage(1, msg)
@@ -203,11 +237,12 @@
configuration_file_name = None
repozo_opts = ['-B']
known_tid_storage_identifier_dict = {}
- recover = False
+ action = None
dry_run = False
status_file = None
status_file_backup_dir = None
recover_status_file = None
+ keep_full_backup_count = None
options = Options()
@@ -223,9 +258,15 @@
options.repozo_file_name = arg
options.repozo_opts[0] = '-R'
- options.recover = True
+ usage(1, 'Only 1 command allowed.')
+ options.action = 'recover'
options.dry_run = True
+ usage(1, 'Only 1 command allowed.')
+ options.action = 'cleanup'
options.repozo_opts.append('%s %s' % (opt, arg))
@@ -250,7 +291,8 @@
options.timestamp_file_path = module.timestamp_file_path
usage(1, msg)
+ for option_id in ('status_file', 'status_file_backup_dir',
setattr(options, option_id, getattr(module, option_id, None))
# XXX: we do not check any option this way, it's too dangerous.
@@ -260,20 +302,27 @@
file_name = os.path.basename(status_file) + '-' + '%04d-%02d-%02d-%02d-%02d-%02d' % time.gmtime()[:6]
- copy(status_file, os.path.sep.join((destination_directory,file_name)))
- log("Written status file backup as %s" % os.path.sep.join((destination_directory,file_name)))
+ copy(status_file, os.path.join(destination_directory, file_name))
+ log("Written status file backup as %s" % os.path.join(destination_directory, file_name))
options = parseargs()
- raise ValueError("Status file path only for recovering")
last_tid_dict = None
+ raise ValueError("Status file path only for recovering")
last_tid_dict = parse(options.recover_status_file)
+ for path in cleanup(options.known_tid_storage_identifier_dict,
+ options.keep_full_backup_count,
+ os.remove(path)
+ return 0
+
repozo_formated_command = '%s %s -r "%%s"' % (options.repozo_file_name, ' '.join(options.repozo_opts))
timestamp_file = open(options.timestamp_file_path, 'r')
timestamp = ''
read_line = ' '
Modified: erp5/trunk/products/TIDStorage/repozo/sample_configuration.py
URL: http://svn.erp5.org/erp5/trunk/products/TIDStorage/repozo/sample_configuration.py?rev=28022&r1=28021&r2=28022&view=diff
==============================================================================
--- erp5/trunk/products/TIDStorage/repozo/sample_configuration.py [utf8] (original)
+++ erp5/trunk/products/TIDStorage/repozo/sample_configuration.py [utf8] Wed Jul 8 13:47:02 2009
@@ -35,3 +35,5 @@
# place to put backuped TIDStorage status_file logs
status_file_backup_dir = '/home/vincent/tmp/repozo'
+# When cleaning up old backups, keep this number of full backups.
+keep_full_backup_count = 3
_______________________________________________
Erp5-report mailing list
Erp5-report at erp5.org
http://mail.nexedi.com/mailman/listinfo/erp5-report
Loading...