From 7a77f5da91b967d25741f85b310e412310bdf27c Mon Sep 17 00:00:00 2001 From: Llloooggg Date: Tue, 20 Oct 2020 12:00:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D1=83=20ssh,=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=B0?= =?UTF-8?q?=D0=BF=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) mode change 100644 => 100755 backup.py diff --git a/backup.py b/backup.py old mode 100644 new mode 100755 index ae1be9c..fc0d3b0 --- a/backup.py +++ b/backup.py @@ -14,7 +14,7 @@ required.add_argument("-hn", help="machine hostname", required=True) required.add_argument("-p", help="path to backup folder", required=True) optional = parser.add_argument_group("optional arguments") optional.add_argument("-n", help="number of backups", type=int, default=2) -optional.add_argument("-sp", help="ssh port", type=int, default=22) +# optional.add_argument("-s", help="ssh port") args = parser.parse_args(argv[1:]) @@ -28,7 +28,10 @@ if args.n > 0: else: print("Error - wrong number of backups!") exit() -ssh_port = parser.sp +# if args.s is not None: +# ssh_port = f" -e 'ssh -p {args.s}'" +# else: +# ssh_port = None dateFormat = "%H-%M-%S--%d-%m-%Y" @@ -56,27 +59,19 @@ for obj in all_objs: except Exception: pass -print() date_dirs.sort(reverse=True) safe_list = [] safe_list.append("sync.log") -print(date_dirs) -print(len(date_dirs)) if len(date_dirs) < backup_num: if not date_dirs or date_dirs[-1] != "00-00-00--01-01-0001": makedirs(path_to_backups + "00-00-00--01-01-0001") safe_list.append("00-00-00--01-01-0001") old_backup = "00-00-00--01-01-0001" -elif date_dirs[-1] == "00-00-00--01-01-0001": - old_backup = "00-00-00--01-01-0001" - date_dirs.pop(-2) else: - old_backup = date_dirs[-1] -print(old_backup) + old_backup = date_dirs[backup_num - 1] safe_list.extend(date_dirs[:backup_num]) -print(safe_list) for obj in all_objs: if obj.name not in safe_list: @@ -90,7 +85,7 @@ new = datetime.now().strftime(dateFormat) write_log("SUCCESS", f"Sync started at {new}\n") sync = call( - f"rsync -aAXcv / --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' --exclude='/run/*' --exclude='/mnt/*' --exclude='/media/*' --exclude='/lost+found'}} {path_to_backups}{old_backup} --delete -e 'ssh -p {ssh_port}'", + f"rsync -aAXcv / --exclude='/dev/*' --exclude='/proc/*' --exclude='/sys/*' --exclude='/tmp/*' --exclude='/run/*' --exclude='/mnt/*' --exclude='/media/*' --exclude='/lost+found'}} {path_to_backups}{old_backup} --delete", shell=True, )