-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateBackup.py
38 lines (33 loc) · 1.38 KB
/
createBackup.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
#!/usr/bin/env python2
# Document information
__author__ = "David Swinkels"
__github__ = "davidswinkels"
__purpose__ = "Part of MSc thesis Geo-Information Science at Wageningen University"
__status__ = "Production"
# Import functions here
import os, os.path
import zipfile
from datetime import datetime
def zip_dir(dirpath, zippath):
"""
Zip directory to a zip file
"""
fzip = zipfile.ZipFile(zippath, 'w', zipfile.ZIP_DEFLATED, allowZip64 = True)
basedir = os.path.dirname(dirpath) + '/'
for root, dirs, files in os.walk(dirpath):
if os.path.basename(root)[0] == '.':
continue # skip hidden directories
dirname = root.replace(basedir, '')
for f in files:
if f[-1] == '~' or (f[0] == '.' and f != '.htaccess'):
# skip backup files and all hidden files except .htaccess
continue
fzip.write(root + '/' + f, dirname + '/' + f)
fzip.close()
# Check current time and add it to filenames
dateTime = str(datetime.now())
filenameScripts = "E:\BackupReportsScripts\Scripts\\" + dateTime[:10] + "Scripts.zip"
filenameReports = "E:\BackupReportsScripts\Reports\\" + dateTime[:10] + "Reports.zip"
# Zip the scripts and reports from workspaces to backup USB drive
zip_dir(dirpath='D:\Workspace\Scripts', zippath=filenameScripts)
zip_dir(dirpath='M:\Thesis\Reports', zippath=filenameReports)