From 11595ef868143df4c826d9c3602c2c56b39c265d Mon Sep 17 00:00:00 2001 From: Alexander Hoerl Date: Thu, 2 Apr 2020 12:12:01 +0200 Subject: [PATCH 01/10] added simple backup of crontab file --- shallow_backup/backup.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shallow_backup/backup.py b/shallow_backup/backup.py index f0ed5d86..b4eda0a8 100644 --- a/shallow_backup/backup.py +++ b/shallow_backup/backup.py @@ -81,6 +81,11 @@ def backup_configs(backup_path, skip=False): safe_mkdir(parent_dir) copyfile(path_to_backup, quote(dest)) + # backup crontab + command = "crontab -l" + dest = "{}/crontab.txt".format(backup_path) + run_cmd_write_stdout(command, dest) + def backup_packages(backup_path, skip=False): """ From ea7714dd0b80f1bf68a9b5c0ea8cf481d6411208 Mon Sep 17 00:00:00 2001 From: Alexander Hoerl Date: Thu, 2 Apr 2020 13:19:14 +0200 Subject: [PATCH 02/10] reinstall crontab --- shallow_backup/reinstall.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 87fc508e..c27a2b67 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -73,6 +73,12 @@ def reinstall_configs_sb(configs_path): elif os.path.isfile(path_to_backup): copyfile(path_to_backup, dest_path) + # reinstall crontab + with open("{0}/crontab.txt".format(configs_path), "r") as f: + for x in f: + cmd = "(crontab -l ; echo \"{0}\") | sort - | uniq - | crontab -".format(x) + run_cmd(cmd) + print_section_header("CONFIG REINSTALLATION COMPLETED", Fore.BLUE) From cf0583eeab8398e9115e89256ecc2569a4579a4c Mon Sep 17 00:00:00 2001 From: Alexander Hoerl Date: Fri, 3 Apr 2020 15:59:57 +0200 Subject: [PATCH 03/10] use os.path.join instead of format --- shallow_backup/backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/backup.py b/shallow_backup/backup.py index b4eda0a8..0b54dc0d 100644 --- a/shallow_backup/backup.py +++ b/shallow_backup/backup.py @@ -83,7 +83,7 @@ def backup_configs(backup_path, skip=False): # backup crontab command = "crontab -l" - dest = "{}/crontab.txt".format(backup_path) + dest = os.path.join(backup_path, "/crontab.txt") run_cmd_write_stdout(command, dest) From c5686318f17f8d68e15f0287dbd72b891271c943 Mon Sep 17 00:00:00 2001 From: Alexander Hoerl Date: Fri, 3 Apr 2020 16:16:22 +0200 Subject: [PATCH 04/10] use os.path.join instead of format; escape any present " characters in the crontab line --- shallow_backup/reinstall.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index c27a2b67..732cb980 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -74,9 +74,12 @@ def reinstall_configs_sb(configs_path): copyfile(path_to_backup, dest_path) # reinstall crontab - with open("{0}/crontab.txt".format(configs_path), "r") as f: + # with open("{0}/crontab.txt".format(configs_path), "r") as f: + with open(os.path.join(configs_path, "/crontab.txt"), "r") as f: for x in f: - cmd = "(crontab -l ; echo \"{0}\") | sort - | uniq - | crontab -".format(x) + # the replace sanitizes the crontab line of any present " characters. + cmd = "(crontab -l ; echo \"{0}\") | sort - | uniq - | crontab -".format( + x.replace('"', '\\"')) run_cmd(cmd) print_section_header("CONFIG REINSTALLATION COMPLETED", Fore.BLUE) From 50ca12aacd2da963092f5e1a5544fffdd99136ed Mon Sep 17 00:00:00 2001 From: Alexander Hoerl Date: Fri, 3 Apr 2020 18:31:33 +0200 Subject: [PATCH 05/10] removed comment --- shallow_backup/reinstall.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 732cb980..471b0eaa 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -74,7 +74,6 @@ def reinstall_configs_sb(configs_path): copyfile(path_to_backup, dest_path) # reinstall crontab - # with open("{0}/crontab.txt".format(configs_path), "r") as f: with open(os.path.join(configs_path, "/crontab.txt"), "r") as f: for x in f: # the replace sanitizes the crontab line of any present " characters. From c181f5d50076d671b2ca3794e23cfb867ec8615b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=B6rl?= Date: Tue, 7 Apr 2020 12:45:03 +0200 Subject: [PATCH 06/10] removed / from path --- shallow_backup/backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/backup.py b/shallow_backup/backup.py index 0b54dc0d..a8823568 100644 --- a/shallow_backup/backup.py +++ b/shallow_backup/backup.py @@ -83,7 +83,7 @@ def backup_configs(backup_path, skip=False): # backup crontab command = "crontab -l" - dest = os.path.join(backup_path, "/crontab.txt") + dest = os.path.join(backup_path, "crontab.txt") run_cmd_write_stdout(command, dest) From a46498cfa70b40dc25427e8d8ab9c9e64a487807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=B6rl?= Date: Tue, 7 Apr 2020 12:50:03 +0200 Subject: [PATCH 07/10] use f string instead of format --- shallow_backup/reinstall.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 471b0eaa..3c05db6f 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -74,11 +74,10 @@ def reinstall_configs_sb(configs_path): copyfile(path_to_backup, dest_path) # reinstall crontab - with open(os.path.join(configs_path, "/crontab.txt"), "r") as f: + with open(os.path.join(configs_path, "crontab.txt"), "r") as f: for x in f: # the replace sanitizes the crontab line of any present " characters. - cmd = "(crontab -l ; echo \"{0}\") | sort - | uniq - | crontab -".format( - x.replace('"', '\\"')) + cmd = f"(crontab -l ; echo \"{x.replace('"', '\\"'))}\") | sort - | uniq - | crontab -" run_cmd(cmd) print_section_header("CONFIG REINSTALLATION COMPLETED", Fore.BLUE) From 2735b44e7fbe9bef5c378a59dfbcbb9ea16b58fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=B6rl?= Date: Tue, 7 Apr 2020 12:55:33 +0200 Subject: [PATCH 08/10] removed unexpected character --- shallow_backup/reinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 3c05db6f..58d0bde0 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -77,7 +77,7 @@ def reinstall_configs_sb(configs_path): with open(os.path.join(configs_path, "crontab.txt"), "r") as f: for x in f: # the replace sanitizes the crontab line of any present " characters. - cmd = f"(crontab -l ; echo \"{x.replace('"', '\\"'))}\") | sort - | uniq - | crontab -" + cmd = f"(crontab -l ; echo \"{x.replace('"', '\\"')}\") | sort - | uniq - | crontab -" run_cmd(cmd) print_section_header("CONFIG REINSTALLATION COMPLETED", Fore.BLUE) From 1cc18448ccc56a9956bb61372717f300d10e418b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=B6rl?= Date: Tue, 7 Apr 2020 13:02:46 +0200 Subject: [PATCH 09/10] fixed SyntaxError --- shallow_backup/reinstall.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 58d0bde0..63aaa8b5 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -77,7 +77,8 @@ def reinstall_configs_sb(configs_path): with open(os.path.join(configs_path, "crontab.txt"), "r") as f: for x in f: # the replace sanitizes the crontab line of any present " characters. - cmd = f"(crontab -l ; echo \"{x.replace('"', '\\"')}\") | sort - | uniq - | crontab -" + sanitized = x.replace('"', '\\"') + cmd = f"(crontab -l ; echo \"{x}\") | sort - | uniq - | crontab -" run_cmd(cmd) print_section_header("CONFIG REINSTALLATION COMPLETED", Fore.BLUE) From 6f8285a5af1456e2d6ec281f86aacd83abecd07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20H=C3=B6rl?= Date: Tue, 7 Apr 2020 13:04:33 +0200 Subject: [PATCH 10/10] fixed SyntaxError --- shallow_backup/reinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 63aaa8b5..fbc75d76 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -78,7 +78,7 @@ def reinstall_configs_sb(configs_path): for x in f: # the replace sanitizes the crontab line of any present " characters. sanitized = x.replace('"', '\\"') - cmd = f"(crontab -l ; echo \"{x}\") | sort - | uniq - | crontab -" + cmd = f"(crontab -l ; echo \"{sanitized}\") | sort - | uniq - | crontab -" run_cmd(cmd) print_section_header("CONFIG REINSTALLATION COMPLETED", Fore.BLUE)