bpo-32713: Fix tarfile.itn for large/negative float values. (GH-5434)
[python-delta-tar] / backup.py
index aa84348..c583790 100644 (file)
--- a/backup.py
+++ b/backup.py
@@ -24,6 +24,7 @@ import os
 import re
 import random
 import shutil
+import sys
 from datetime import datetime
 from functools import partial
 
@@ -78,19 +79,27 @@ if __name__ == "__main__":
                                        ''           open uncompressed;
                                        'gz'         open with gzip compression;
                                        'bz2'        open with bzip2 compression;
-                                       '#gz.aes128' open an aes128 encrypted stream of gzip
-                                                    compressed tar blocks;
-                                       '#aes128'    open an aes128 encrypted stream of tar
-                                                    blocks.
+                                       '#gz'        encrypted stream of individually
+                                                    compressed tar blocks.
+                            To enable encryption, supply a password.
                             """)
     parser.add_argument("-t", "--targetpath", help="Target path directory.")
     parser.add_argument("-s", "--sourcepath", help="Source path directory.")
-    parser.add_argument("-p", "--password", default='',
-                        help="Password for symmetric encryption.")
+    epw = os.getenv ("PDTCRYPT_PASSWORD")
+    parser.add_argument("-p", "--password",
+                        default=epw.strip () if epw is not None else None,
+                        help="Password for symmetric encryption. "
+                             "The environment variable PDTCRYPT_PASSWORD should "
+                             "be preferred to this. Enables encryption.")
     parser.add_argument("-v", "--volsize", default=None,
                         help="Maximum volume size, in megabytes.")
     parser.add_argument("-r", "--restore", action='store_true',
                         help="Restore a backup.")
+    parser.add_argument("-R", "--recover", action='store_true',
+                        help="Recover a potentially damaged backup with an index "
+                        "file. **Caution**: recovery mode is insecure; it ignores "
+                        "data integrity checks on encrypted backup sets which may "
+                        "allow unauthorized decryption of confidential information.")
     parser.add_argument("-f", "--full", action='store_true',
                         help="Create a full backup.")
     parser.add_argument("-d", "--diff", action='store_true',
@@ -140,11 +149,23 @@ if __name__ == "__main__":
             deltatar.restore_backup(args.targetpath, backup_indexes_paths=args.indexes)
         else:
             deltatar.restore_backup(args.targetpath, backup_tar_path=args.sourcepath)
+    elif args.recover:
+        if args.sourcepath is not None:
+            print("Disaster recovery conflicts with --sourcepath; please supply"
+                  " an\nindex file (--indexes).", file=sys.stderr)
+        failed = deltatar.recover_backup(args.targetpath,
+                                         backup_indexes_paths=args.indexes)
+        if len (failed) > 0:
+            logger = logging.getLogger('deltatar.DeltaTar')
+            print ("%d files could not be restored:" % len (failed))
+            for i, f in enumerate (failed):
+                print ("   [%d] %s (%s)" % (i, f [0], f [1]))
+
     elif args.equals:
         check_equal_dirs(os.path.abspath(args.sourcepath), os.path.abspath(args.targetpath), deltatar)
     else:
-        import sys
         print("Nothing to do.\nPlease specify one of --full, --diff, --list-files, "
               "--restore, --equals.\n", file=sys.stderr)
         parser.print_help(file=sys.stderr)
 
+