Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.

Commit a6722da

Browse files
committed
Merge pull request #1 from ebright/variables
Variables
2 parents f171eb7 + 2150a2b commit a6722da

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

backup.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818

1919
d = datetime.datetime.now()
2020
date_format = "%Y_%m_%d_%H_%M"
21-
log_file = "/tmp/backup.log"
21+
log_file = "/tmp/freenas-backup.log"
2222
db_file = "/data/freenas-v1.db"
2323
bk_path = "/tmp/"
2424
backup_name = "backup"
25-
latest_name = "current"
25+
archive_name = "archive"
2626
ext = ".db"
2727

2828
matched = None
2929
fname = None
30-
latest_len = len(latest_name)
30+
backup_len = len(backup_name)
3131

3232
console = logging.StreamHandler()
3333
console.setLevel(logging.INFO)
@@ -39,10 +39,8 @@
3939
datefmt='%m/%d/%Y %H:%M:%S')
4040
logging.getLogger('').addHandler(console)
4141

42-
logging.info(latest_len)
43-
4442
if os.stat(log_file)[6]==0:
45-
logging.debug('Version 1.0 build 15')
43+
logging.debug('Version 1.0 build 16')
4644
logging.debug('Automatic Backup Script for FreeNAS Configuration File')
4745
logging.debug('Script Created By: Eric Bright Copyright (C) 2013')
4846
logging.debug('https://github.com/ebright/FreeNas_Config/')
@@ -51,7 +49,7 @@
5149
os.chdir(bk_path)
5250
logging.debug('Searching for previous backup in ' + bk_path )
5351
for files in os.listdir("."):
54-
if files.startswith(latest_name):
52+
if files.startswith(backup_name):
5553
fname = files
5654
bk_file = bk_path + files
5755
matched = True
@@ -64,14 +62,14 @@
6462
logging.info('Configuration has not changed. Aborting backup')
6563
sys.exit()
6664
else:
67-
logging.debug('Configuration changed. renaming previous backup')
68-
logging.debug(bk_file + ' >> ' + bk_path + backup_name + fname[latest_len:])
69-
shutil.move(bk_file, bk_path + backup_name + fname[latest_len:])
70-
logging.info('Creating backup ' + bk_path + latest_name + '_' + d.strftime(date_format) + ext)
71-
shutil.copy2(db_file, bk_path + latest_name + '_' + d.strftime(date_format) + ext)
65+
logging.debug('Configuration changed. Archiving previous backup')
66+
logging.debug(bk_file + ' >> ' + bk_path + archive_name + fname[backup_len:])
67+
shutil.move(bk_file, bk_path + archive_name + fname[backup_len:])
68+
logging.info('Creating backup ' + bk_path + backup_name + '_' + d.strftime(date_format) + ext)
69+
shutil.copy2(db_file, bk_path + backup_name + '_' + d.strftime(date_format) + ext)
7270

7371
else:
74-
bk_file = bk_path + latest_name + '_' + d.strftime(date_format) + ext
72+
bk_file = bk_path + backup_name + '_' + d.strftime(date_format) + ext
7573
logging.info('No previous backup found. Create new backup: ' + bk_file)
7674
shutil.copy2(db_file, bk_file)
7775
sys.exit()

0 commit comments

Comments
 (0)