Anonymous avatar Anonymous committed 5674d29

- use temp dirs for duplicity, etc.

Comments (0)

Files changed (1)

backups/synthetic.py

                 for key in source_bucket.list()
             ])
 
+def _delete_bucket(s3, name):
+    bucket = s3.lookup(name)
+    if bucket is not None:
+        bucket.delete_keys(bucket.list())
+        bucket.delete()
+
 def run_synthetic(config, args):
     config_dict = base._get_config(config, args)
     copy_pool = Pool(10, _global_connect, (config_dict, ))
 
-    cmd_options = []
-    base._setup_command(cmd_options, config_dict)
-    base._render_options_args(config_dict, cmd_options)
+    _global_connect(config_dict)
 
     target_url = config_dict['target_url']
 
                     "tmp_source": tmp_source,
                     "tmp_dest": tmp_dest
                     }
-    run_duplicity_cmd = functools.partial(
-                                duplicity_cmd, cmd_options, replace_dict)
-
-    s3 = boto.connect_s3()
 
     # create temp buckets, dir
     local_tmp_dir = tempfile.mkdtemp()
+    duplicity_cache_dir = tempfile.mkdtemp()
+
+    config_dict['archive-dir'] = duplicity_cache_dir
+
+    _delete_bucket(s3, tmp_source)
+    _delete_bucket(s3, tmp_dest)
+
     tmp_source_bucket = s3.create_bucket(tmp_source)
     tmp_dest_bucket = s3.create_bucket(tmp_dest)
 
     try:
+        cmd_options = []
+        base._setup_command(cmd_options, config_dict)
+        base._render_options_args(config_dict, cmd_options)
+        run_duplicity_cmd = functools.partial(
+                                duplicity_cmd, cmd_options, replace_dict)
+
+        
         source_bucket = s3.lookup(source_bucket_name)
 
         all_source_keys = set(k.key for k in source_bucket.list())
 
     finally:
         # 8. remove tmp buckets
-        tmp_source_bucket.delete_keys(tmp_source_bucket.list())
-        tmp_source_bucket.delete()
-        tmp_dest_bucket.delete_keys(tmp_dest_bucket.list())
-        tmp_dest_bucket.delete()
         shutil.rmtree(local_tmp_dir)
+        shutil.rmtree(duplicity_cache_dir)
+        _delete_bucket(s3, tmp_source)
+        _delete_bucket(s3, tmp_dest)
 
 
 def main(argv=None, **kwargs):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.