[PATCH] improved behaviour of tools/backup/hot-backup.py
Roberto Reale <roberto.reale82 <at> gmail.com>
2015-10-02 15:44:34 GMT
enclosed is a puny patch I wrote against the script
When creating a backup archive of a live repository, the "legacy"
behaviour of the script is simply to call tar.add() on a hotdump copy.
This has, however, an inconvenience when the original repository is on
a POSIX filesystem and the hotcopy dump is written e.g. on a CIFS
filesystem, thus leading to a possible "permission leakage".
My patch changes this behaviour by letting the script build up the
archive file by file, and paying special care in copying the
permissions for each file from the repository itself rather than from
the hotcopy dump.
Do you think it would be useful?
* tools/backup/hot-backup.py.in: Always save correct file
permissions in tar archives.
--- tools/backup/hot-backup.py.in (revision 1706408)
+++ tools/backup/hot-backup.py.in (working copy)
<at> <at> -292,7 +292,26 <at> <at> if archive_type:
tar = tarfile.open(archive_path, 'w:' + archive_type)
- tar.add(backup_subdir, os.path.basename(backup_subdir))
+ # Build up the archive file by file, paying special care
+ # in replicating the permissions for each file from
+ # the repository itself rather than from the hotcopy dump.
+ # This can be useful in such cases when the original
+ # repository is on a POSIX filesystem and the hotcopy
+ # dump is written e.g. on a CIFS filesystem, thus leading
+ # to a possible "permission leakage" were the archive
+ # built directly from hotcopy dump via tar.add().
+ for dirpath, dirnames, filenames in os.walk(backup_subdir, followlinks=True):
+ for leafname in dirnames + filenames:
+ backup_based_path = os.path.join(dirpath, leafname)
+ relpath = os.path.relpath(backup_based_path, backup_subdir)
+ repo_based_path = os.path.join(repo_dir, relpath)
+ tarinfo = tar.gettarinfo(backup_based_path, os.path.join(repo, relpath))
+ tarinfo.mode = os.stat(repo_based_path).st_mode
+ if tarinfo.isreg():
+ with open(backup_based_path, "rb") as f:
+ tar.addfile(tarinfo, f)
except ImportError, e:
err_msg = "Import failed: " + str(e)