-
Notifications
You must be signed in to change notification settings - Fork 0
/
backup-pro.py
84 lines (69 loc) · 3.33 KB
/
backup-pro.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/python3
########################################################################
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <http://www.gnu.org/licenses/>.#
# #
# Copyright (C) 2014 by Marco Guerrini #
########################################################################
import argparse
from libbackuppro import BackupPro
import libitunitsconversion
# Setting arguments
argparse = argparse.ArgumentParser(prog='backup-pro', description='A program to generate backups')
argparse.add_argument('--version', action='version', version='%(prog)s version 1.0.0')
argparse.add_argument('patch', action='store', type=str, help='patch to backup')
argparse.add_argument('--olddatabase', '-d', action='store', help='old database patch to make an incremental bakcup')
argparse.add_argument('--split', '-s', action='store', help='in how many bytes split the backup? You can use the suffix MB and GB. Insert CD or DVD of 700MB or 4.7GB')
#argparse.add_argument('--buildiso', '-b', action='store_true', help='if the software have to build the iso to burn backups on CDs or DVDs')
args = argparse.parse_args()
# Start backup
bp = BackupPro(str(args.patch))
# Get all files
files = bp.getFiles()
# Get all sums
sums = bp.getSums(files)
# If is isset and old database remove the files which have the same name and sums:
if(args.olddatabase != None):
olddb = bp.dbparse(args.olddatabase)
#commonFiles = bp.getFilesInTwoListsAndSums(files, sums, olddb[0], olddb[1])
toBackupFiles = bp.getFilesEditedAndSums(files, sums, olddb[0], olddb[1])
removedFiles = bp.deleteFilesOfThePreviousBackup(files, sums, olddb[0], olddb[1])
deleteScript = bp.generateDeleteScript(removedFiles)
else:
toBackupFiles = files
# Generate a new database of files and md5
database = bp.dbgenerator(files, sums)
# Set if split files
if args.split == None:
split = False
supportSize = 0
else:
split = True
supportSize = str(args.split)
supportSize = libitunitsconversion.getBytes(supportSize)
# Get the patches of files
newFiles, oldfiles = bp.getWhereCopyFiles(toBackupFiles, split, supportSize)
# Copy the files
bp.copy(oldfiles, newFiles)
# Create the delete script
if(args.olddatabase != None):
ds = open(bp.destinationPrefix + '1/deleteScript.sh', 'w')
ds.write(deleteScript)
ds.close()
# Write the database
databaseF = open(bp.destinationPrefix + '1/database.md5', 'w')
databaseF.write(database)
databaseF.close()
# Build the iso
#if args.buildiso:
# bp.makeIso();