Commit 7c9d3e6f authored by Robert Spencer's avatar Robert Spencer
Browse files

Add comand line parameter and code for testing


Signed-off-by: Robert Spencer's avatarRobert Spencer <rspencer@lbsd.net>
parent 975fdb84
...@@ -40,6 +40,12 @@ group.add_argument("-w", "--weekly", action="store_true", help="Do weekly backup ...@@ -40,6 +40,12 @@ group.add_argument("-w", "--weekly", action="store_true", help="Do weekly backup
parser.add_argument( parser.add_argument(
"-o", "--only", help="Only do a backup of the specified lv", metavar="lv_name" "-o", "--only", help="Only do a backup of the specified lv", metavar="lv_name"
) )
parser.add_argument(
"-t",
"--test",
action="store_true",
help="Don't do anything, only show what would have been run.",
)
args = parser.parse_args() args = parser.parse_args()
if args.daily: if args.daily:
...@@ -50,7 +56,10 @@ else: ...@@ -50,7 +56,10 @@ else:
print("error: You need to specify a period [daily or weekly].") print("error: You need to specify a period [daily or weekly].")
sys.exit(2) sys.exit(2)
CONFIG_FILE = "/etc/backstep-traceback/backstep-traceback-auto.ini" if not args.test:
CONFIG_FILE = "/etc/backstep-traceback/backstep-traceback-auto.ini"
else:
CONFIG_FILE = "backstep-traceback-auto.ini"
if not os.path.exists(CONFIG_FILE): if not os.path.exists(CONFIG_FILE):
print("error: backup is not configured.") print("error: backup is not configured.")
...@@ -74,18 +83,20 @@ report_email = config.get(PERIOD, "report_email") ...@@ -74,18 +83,20 @@ report_email = config.get(PERIOD, "report_email")
server_host = config.get(PERIOD, "server_host") server_host = config.get(PERIOD, "server_host")
server_key = config.get(PERIOD, "server_key") server_key = config.get(PERIOD, "server_key")
if not os.path.exists(server_key): if not args.test:
print("error: " + server_key + " does not exist.") if not os.path.exists(server_key):
sys.exit(2) print("error: " + server_key + " does not exist.")
sys.exit(2)
server_path = config.get(PERIOD, "server_path") server_path = config.get(PERIOD, "server_path")
server_port = config.getint(PERIOD, "server_port") server_port = config.getint(PERIOD, "server_port")
server_user = config.get(PERIOD, "server_user") server_user = config.get(PERIOD, "server_user")
zabbix_config = config.get(PERIOD, "zabbix_config") zabbix_config = config.get(PERIOD, "zabbix_config")
if not os.path.exists(zabbix_config): if not args.test:
print("error: " + zabbix_config + " does not exist.") if not os.path.exists(zabbix_config):
sys.exit(2) print("error: " + zabbix_config + " does not exist.")
sys.exit(2)
if args.verbose: if args.verbose:
syncopts = ["--debug"] syncopts = ["--debug"]
...@@ -105,12 +116,15 @@ for lv in ast.literal_eval(config.get(PERIOD, "backup_lvs")): ...@@ -105,12 +116,15 @@ for lv in ast.literal_eval(config.get(PERIOD, "backup_lvs")):
bind_mount_args = [] bind_mount_args = []
lvm_snapshot_args = [] lvm_snapshot_args = []
if os.path.exists("/dev/lvm-raid/" + lv): if not args.test:
VG = "lvm-raid" if os.path.exists("/dev/lvm-raid/" + lv):
elif os.path.exists("/dev/lvm-cache/" + lv): VG = "lvm-raid"
VG = "lvm-cache" elif os.path.exists("/dev/lvm-cache/" + lv):
VG = "lvm-cache"
else:
continue
else: else:
continue VG = "lvm-raid"
if lv == "root": if lv == "root":
bind_mount_args.append("--bind-mount") bind_mount_args.append("--bind-mount")
...@@ -149,4 +163,7 @@ for lv in ast.literal_eval(config.get(PERIOD, "backup_lvs")): ...@@ -149,4 +163,7 @@ for lv in ast.literal_eval(config.get(PERIOD, "backup_lvs")):
) )
) )
EXIT_CODE = subprocess.call(command_line) if not args.test:
EXIT_CODE = subprocess.call(command_line)
else:
print(command_line)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment