|
@@ -0,0 +1,54 @@
|
|
1
|
+#!/usr/bin/env python
|
|
2
|
+# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+# Regular expressions matching files and folders to exclude from the backup
|
|
5
|
+EXCLUDES = [
|
|
6
|
+ "/Cache",
|
|
7
|
+ "/OfflineCache/",
|
|
8
|
+ "\.mfasl$",
|
|
9
|
+ "/urlclassifier",
|
|
10
|
+ "/lock$",
|
|
11
|
+ "/parent.lock$",
|
|
12
|
+ "/.parentlock$",
|
|
13
|
+]
|
|
14
|
+
|
|
15
|
+import time, os, os.path, re, sys, tarfile
|
|
16
|
+
|
|
17
|
+if len(sys.argv) != 2:
|
|
18
|
+ print "Usage: %s path_to_profile" % sys.argv[0]
|
|
19
|
+ sys.exit(1)
|
|
20
|
+
|
|
21
|
+profile_path = sys.argv[1]
|
|
22
|
+profile_name = os.path.basename(profile_path)
|
|
23
|
+date = time.strftime("%Y%m%d_%H%M%S")
|
|
24
|
+archive_name = "%s-%s.tar.bz2" % (profile_name, date)
|
|
25
|
+
|
|
26
|
+# Compile exclusion regexps
|
|
27
|
+EXCLUDES_RE = []
|
|
28
|
+for regexp in EXCLUDES:
|
|
29
|
+ r = re.compile(regexp)
|
|
30
|
+ EXCLUDES_RE.append(r)
|
|
31
|
+
|
|
32
|
+# Uncompressed size
|
|
33
|
+total_size = 0
|
|
34
|
+
|
|
35
|
+# Exclusion decision function
|
|
36
|
+def is_excluded(filename):
|
|
37
|
+ global EXCLUDES_RE, total_size
|
|
38
|
+ for regexp in EXCLUDES_RE:
|
|
39
|
+ if regexp.search(filename):
|
|
40
|
+ return True
|
|
41
|
+ total_size += os.path.getsize(filename)
|
|
42
|
+ return False
|
|
43
|
+
|
|
44
|
+# Open the destination tar archive
|
|
45
|
+tar = tarfile.open(archive_name, 'w:bz2')
|
|
46
|
+
|
|
47
|
+# Add the data to the archive
|
|
48
|
+tar.add(profile_path, profile_name, exclude=is_excluded)
|
|
49
|
+
|
|
50
|
+tar.close()
|
|
51
|
+
|
|
52
|
+# Display archive name and sizes
|
|
53
|
+print "Profile saved to %s" % archive_name
|
|
54
|
+print "%.1f MB --> %.1f MB" % (total_size/(1024**2), os.path.getsize(archive_name)/(1024**2))
|