Permalink
Browse files

An ability to choose paths to restore

  • Loading branch information...
1 parent a510cd3 commit d969a96c524cbecb9f4f9b6877f3dabece99b3ed @KonishchevDmitry committed Dec 21, 2012
Showing with 19 additions and 2 deletions.
  1. +9 −1 pyvsb/backup.py
  2. +10 −1 pyvsb/main.py
View
@@ -414,7 +414,7 @@ def close(self):
self.__state = _STATE_CLOSED
- def restore(self):
+ def restore(self, paths_to_restore = None):
"""Restores the backup.
Returns True if all files has been successfully restored.
@@ -449,6 +449,14 @@ def restore(self):
for tar_info in files:
path = "/" + tar_info.name
+
+ if paths_to_restore is not None:
+ for path_to_restore in paths_to_restore:
+ if path == path_to_restore or path.startswith(path_to_restore + os.path.sep):
+ break
+ else:
+ continue
+
restore_path = os.path.join(self.__restore_path, tar_info.name)
LOG.info("Restoring '%s'...", path)
View
@@ -50,6 +50,9 @@ def main():
parser.add_argument("-r", "--restore", metavar = "BACKUP_PATH",
default = None, help = "restore the specified backup")
+ parser.add_argument("paths_to_restore", nargs = "*",
+ metavar = "PATH_TO_RESTORE", help = "Path to restore (default is /)")
+
parser.add_argument("-d", "--debug", action = "store_true",
help = "turn on debug messages")
@@ -58,6 +61,10 @@ def main():
args = parser.parse_args()
+ if args.restore is None and args.paths_to_restore:
+ parser.print_help()
+ sys.exit(os.EX_USAGE)
+
log_level = logging.WARNING if args.cron else logging.INFO
setup_logging(args.debug, log_level)
@@ -77,8 +84,10 @@ def main():
raise Error("Backup failed: {}", e)
else:
try:
+ paths_to_restore = [ os.path.abspath(path) for path in args.paths_to_restore ]
+
with Restore(os.path.abspath(args.restore)) as restorer:
- success = restorer.restore()
+ success = restorer.restore(paths_to_restore or None)
except Exception as e:
raise Error("Restore failed: {}", e)
except Exception as e:

0 comments on commit d969a96

Please sign in to comment.