mirror of
https://github.com/FAUSheppy/no-secrets-athq-ansible
synced 2025-12-07 11:51:36 +01:00
fix: various check size script tweaks
This commit is contained in:
@@ -1,14 +1,17 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import argparse
|
import argparse
|
||||||
|
import json
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Backup Dir Size helper")
|
parser = argparse.ArgumentParser(description="Backup Dir Size helper")
|
||||||
parser.add_argument('PATH')
|
parser.add_argument('PATH')
|
||||||
|
parser.add_argument('--save-new-size', action='store_const',
|
||||||
|
default=False, const=True)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# check parameter #
|
# check parameter #
|
||||||
@@ -22,7 +25,8 @@ if __name__ == "__main__":
|
|||||||
print("Path does not exist ({}".format(args.PATH))
|
print("Path does not exist ({}".format(args.PATH))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
savepath = os.path.join("/", args.PATH.replace("/", "-"))
|
savedir = "/opt/backup-info"
|
||||||
|
savepath = os.path.join(savedir, args.PATH.lstrip("/").replace("/", "-"))
|
||||||
currentSize = 0
|
currentSize = 0
|
||||||
if os.path.isfile(savepath):
|
if os.path.isfile(savepath):
|
||||||
with open(savepath) as f:
|
with open(savepath) as f:
|
||||||
@@ -33,9 +37,14 @@ if __name__ == "__main__":
|
|||||||
size = int(p.stdout.split("\n")[-2].split("\t")[0])
|
size = int(p.stdout.split("\n")[-2].split("\t")[0])
|
||||||
|
|
||||||
if currentSize and currentSize == size:
|
if currentSize and currentSize == size:
|
||||||
sys.exit(2)
|
result = { "state" : "ok", "old" : currentSize, "new" : size }
|
||||||
else:
|
else:
|
||||||
print("Directory has changed {} to {}".format(currentSize, size))
|
result = { "state" : "changed", "old" : currentSize, "new" : size }
|
||||||
|
|
||||||
|
|
||||||
|
if args.save_new_size:
|
||||||
with open(savepath, "w") as f:
|
with open(savepath, "w") as f:
|
||||||
f.write(str(size))
|
f.write(str(size))
|
||||||
sys.exit(0)
|
|
||||||
|
# return result
|
||||||
|
print(json.dumps(result))
|
||||||
|
|||||||
@@ -13,6 +13,12 @@
|
|||||||
state: directory
|
state: directory
|
||||||
mode: 711
|
mode: 711
|
||||||
|
|
||||||
|
- name: Ensure backup info dir exists and accessible
|
||||||
|
file:
|
||||||
|
name: /opt/backup-info/
|
||||||
|
state: directory
|
||||||
|
mode: 700
|
||||||
|
|
||||||
- name: Copy Backup Helper script
|
- name: Copy Backup Helper script
|
||||||
copy:
|
copy:
|
||||||
src: check_dir_size_for_backup.py
|
src: check_dir_size_for_backup.py
|
||||||
|
|||||||
Reference in New Issue
Block a user