2024-08-16 17:40:24 +02:00
|
|
|
import config/init
|
|
|
|
import config/args
|
|
|
|
import borg/borg
|
2024-08-23 10:50:53 +02:00
|
|
|
import restic/restic
|
|
|
|
import model/encryption_type
|
|
|
|
import utils/actions
|
2024-08-27 22:16:31 +02:00
|
|
|
import model/log_type
|
|
|
|
import os
|
2024-08-16 17:40:24 +02:00
|
|
|
|
2024-08-27 21:21:21 +02:00
|
|
|
proc showVersion() =
|
|
|
|
echo "Norg Version: ", VERSION
|
|
|
|
quit(0)
|
|
|
|
|
2024-09-11 22:08:27 +02:00
|
|
|
proc startLogger(nc: NorgConfig, log_info: LogInfo) =
|
2024-08-27 22:39:21 +02:00
|
|
|
initLogger(log_info.level, "[$levelname] ")
|
2024-08-27 22:16:31 +02:00
|
|
|
|
2024-08-16 17:40:24 +02:00
|
|
|
proc start() =
|
|
|
|
parseArgs()
|
|
|
|
norg_config.args = norg_args
|
2024-08-27 21:21:21 +02:00
|
|
|
if norg_args.show_version:
|
|
|
|
showVersion()
|
2024-11-25 12:15:15 +01:00
|
|
|
elif norg_args.command == GEN_CONF:
|
|
|
|
var config_file = "norg_backup.toml"
|
|
|
|
if norg_args.config_file != "":
|
|
|
|
config_file = norg_args.config_file
|
|
|
|
generateConfigFile(config_file)
|
2024-08-27 21:21:21 +02:00
|
|
|
elif norg_args.config_file != "":
|
2024-08-27 20:58:50 +02:00
|
|
|
norg_config = parseConfigFile(norg_args.config_file)
|
2024-08-27 22:39:21 +02:00
|
|
|
echo norg_config.log_info.level
|
2024-09-11 22:08:27 +02:00
|
|
|
norg_config.startLogger(norg_config.log_info)
|
2024-08-27 21:21:21 +02:00
|
|
|
if norg_config.source_directories.len > 0 and norg_config.repositories.len > 0:
|
|
|
|
run_actions(norg_config.actions.before_everything)
|
|
|
|
for repo in norg_config.repositories:
|
|
|
|
run_actions(norg_config.actions.before_actions)
|
|
|
|
case repo.tool
|
|
|
|
of BORG:
|
|
|
|
borg.execute(norg_config, repo)
|
|
|
|
of RESTIC:
|
|
|
|
restic.execute(norg_config, repo)
|
|
|
|
run_actions(norg_config.actions.after_actions)
|
|
|
|
run_actions(norg_config.actions.after_everything)
|
|
|
|
delEncryptionPassphraseInfo()
|
|
|
|
else:
|
|
|
|
echo "No Config File Provided"
|
2024-08-16 17:40:24 +02:00
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
start()
|
2024-09-03 16:20:44 +02:00
|
|
|
echo "Always remember to check your backups!"
|
2024-08-27 22:16:31 +02:00
|
|
|
# sleep for a bit to let logs finish
|
|
|
|
sleep 5
|
2024-09-03 16:20:44 +02:00
|
|
|
|