diff --git a/shallow_backup/backup.py b/shallow_backup/backup.py index f0ed5d86..a8823568 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 = os.path.join(backup_path, "crontab.txt") + run_cmd_write_stdout(command, dest) + def backup_packages(backup_path, skip=False): """ diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 87fc508e..fbc75d76 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -73,6 +73,14 @@ def reinstall_configs_sb(configs_path): elif os.path.isfile(path_to_backup): copyfile(path_to_backup, dest_path) + # reinstall crontab + 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. + sanitized = x.replace('"', '\\"') + cmd = f"(crontab -l ; echo \"{sanitized}\") | sort - | uniq - | crontab -" + run_cmd(cmd) + print_section_header("CONFIG REINSTALLATION COMPLETED", Fore.BLUE)