Advertisement
Guest User

>x

a guest
Jan 17th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import os
  2. import subprocess
  3. import shutil
  4. from datetime import datetime
  5.  
  6. def getOutput(command):
  7.     o, _e = subprocess.Popen(['bash', '-c', "time {} 2>&1".format(command), './test.out'],
  8.     stdout = subprocess.PIPE, stderr=subprocess.PIPE).communicate()
  9.     return o.decode()
  10.  
  11. now = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")
  12. size = int(getOutput("du -c /mnt/Archiwum_Lokalne | grep 'total'").split('\t')[0])
  13. leftover = 100000 - size
  14. print("backup.py - {}".format(now))
  15. print("backup.py - Zostalo miejsca: {} KB".format(leftover))
  16. if leftover < 30000:
  17.     print("backup.py - Kasowanie starych kopii")
  18.     dirlist = os.listdir("/mnt/Archiwum_Lokalne")
  19.     dirlist.sort(reverse=True)
  20.     shutil.rmtree("/mnt/Archiwum_Lokalne/{}".format(dirlist[0]))
  21.    
  22. os.system("mkdir /mnt/Archiwum_Lokalne/Archiwum_{}".format(now))
  23. os.system("rsync -a /home/. /mnt/Archiwum_Lokalne/Archiwum_{}".format(now))
  24. print("backup.py - Ukonczono zapisywanie Archiwum_{}".format(now))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement