Version 19.2
[livecd.git] / tools / mkbackup.py
blobd08532cbd46e33224f77e3dc131ce61598b49167
1 #!/usr/bin/python
3 import os
4 import sys
5 import subprocess
6 import shutil
7 import tempfile
8 import re
10 #dump -0 / -f dump.img && dd if=/dev/zero of=filesystem.img bs=2M count=1000 && losetup /dev/loop0 filesystem.img && mkdir filesystem && mke2fs -j /dev/loop0 && mount -t ext3 /dev/loop0 -o loop filesystem && cd filesystem && restore -r -f ../dump.img && cd ../ && umount filesystem && losetup -d /dev/loop0
14 def main():
15 def usage():
16 sys.exit(1)
19 def mktmpdir():
20 tmpdir = tempfile.mkdtemp()
21 return tmpdir
23 def mktmpfile():
24 tmpfile = tempfile.mkstemp()
25 return tmpfile[1]
27 def size(ent):
28 current = os.stat(ent).st_size
29 return current
31 def mkempty(bs, count):
32 image = tempfile.mkstemp()
33 args = ("/bin/dd", "if=/dev/zero", "of=%s"%image, "bs=%s"%bs, "count=%s"%count)
34 execute(args)
35 return image
37 def dump(ent, file):
38 args = ("/sbin/dump", "-0", ent, "-f", file)
39 execute(args)
41 def restore():
42 pass
45 def mkcopy():
46 pass
48 def getrootents():
49 ents = list()
50 args = ("/bin/df", "-lh")
51 data = execute(args, needdata=True)
52 lines = data.split('\n')
54 for line in lines:
55 if re.search(r"/dev/", line) and not re.search(r"tmpfs", line):
56 ent = re.search(r"/dev/[-0-9A-Za-z]+", line)
57 ents.append(ent.group())
58 return ents
63 def execute(args, needdata=False):
64 if needdata is False:
65 rc = subprocess.call(args)
66 else:
67 rc = subprocess.Popen(args, stdout=subprocess.PIPE).communicate()[0]
69 return rc
72 def setup():
74 dumpfiles = list()
75 ents = getrootents()
76 for ent in ents:
77 dumpfile = mktmpfile()
78 dump(ent, dumpfile)
79 dumpfiles.append(dumpfile)
81 tsize = 0
82 for dumpfile in dumpfiles:
83 tsize = size(dumpfile) + tsize
85 bs = 2048
86 count = (tsize / 2048)
88 target = mkempty(bs, count)
90 setup()
91 rc = 0
92 return rc
98 if __name__ == "__main__":
99 sys.exit(main())