-def create_targz(tmp, files, start_time, options, user, state, set_state):
- if os.path.exists(LAST_BACKUP):
- os.remove(LAST_BACKUP)
-
- t = tarfile.open(name=LAST_BACKUP, mode = 'w:gz')
+def create_targz(tmp, files, start_time, options, user, state, set_state, file_format):
+ now = datetime.datetime.now()
+ domain = re.match('[\w-]+\.[\w-]+(\.[\w-]+)*', djsettings.APP_URL)
+ if domain:
+ domain = '_'.join(domain.get(0).split('.'))
+ else:
+ domain = 'localhost'
+
+ fname = "%s-%s" % (domain, now.strftime('%Y%m%d%H%M'))
+ if file_format == 'zip':
+ full_fname = "%s.zip" % fname
+ else:
+ full_fname = "%s.tar.gz" % fname
+
+ if file_format == 'zip':
+ t = zipfile.ZipFile(os.path.join(selfsettings.EXPORTER_BACKUP_STORAGE, full_fname), 'w')
+
+ def add_to_file(f, a):
+ t.write(f, a)
+ else:
+ t = tarfile.open(os.path.join(selfsettings.EXPORTER_BACKUP_STORAGE, full_fname), mode = 'w:gz')
+
+ def add_to_file(f, a):
+ t.add(f, a)