2019-04-15 16:31:08 +00:00
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
2019-04-15 15:25:42 +00:00
|
|
|
from restic_volume_backup.config import Config
|
|
|
|
from restic_volume_backup.containers import RunningContainers
|
2019-04-13 17:04:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2019-04-15 16:31:08 +00:00
|
|
|
args = parse_args()
|
2019-04-13 17:04:54 +00:00
|
|
|
|
|
|
|
Config.check()
|
|
|
|
|
|
|
|
containers = RunningContainers()
|
|
|
|
|
2019-04-15 16:31:08 +00:00
|
|
|
if args.action == 'status':
|
2019-04-15 14:16:06 +00:00
|
|
|
containers.print_services()
|
|
|
|
# volumes = containers.volume_mounts()
|
|
|
|
# for vol in volumes:
|
|
|
|
# print(vol)
|
|
|
|
# print(vol.mount_string())
|
2019-04-13 17:04:54 +00:00
|
|
|
|
2019-04-15 14:16:06 +00:00
|
|
|
# binds = containers.bind_mounts()
|
|
|
|
# for vol in binds:
|
|
|
|
# print(binds)
|
|
|
|
# print(vol.mount_string())
|
2019-04-13 17:04:54 +00:00
|
|
|
|
2019-04-15 16:31:08 +00:00
|
|
|
elif args.mode == 'backup':
|
2019-04-15 14:16:06 +00:00
|
|
|
print("Starting backup ..")
|
2019-04-13 23:35:14 +00:00
|
|
|
# TODO: Errors when repo already exists
|
2019-04-15 14:16:06 +00:00
|
|
|
# restic.init_repo(Config.repository)
|
2019-04-13 17:04:54 +00:00
|
|
|
|
2019-04-13 23:35:14 +00:00
|
|
|
# for vol in containers.backup_volumes():
|
|
|
|
# restic.backup_volume(Config.repository, vol)
|
|
|
|
|
2019-04-15 16:31:08 +00:00
|
|
|
elif args.mode == 'snapshots':
|
2019-04-13 18:12:25 +00:00
|
|
|
restic.snapshots(Config.repository)
|
2019-04-13 17:04:54 +00:00
|
|
|
|
2019-04-13 23:35:14 +00:00
|
|
|
|
2019-04-15 16:31:08 +00:00
|
|
|
def parse_args():
|
|
|
|
parser = argparse.ArgumentParser(prog='restic_volume_backup')
|
|
|
|
parser.add_argument(
|
|
|
|
'action',
|
|
|
|
choices=['status', 'backup'],
|
|
|
|
)
|
|
|
|
return parser.parse_args()
|
|
|
|
|
|
|
|
|
2019-04-13 17:04:54 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|