fork download
  1. #!/usr/bin/env python3
  2.  
  3. import os
  4. import time
  5.  
  6.  
  7. def backup(sources, destination):
  8. os.makedirs(destination, exist_ok=True)
  9.  
  10. archive = os.path.join(destination, time.strftime('%Y%m%d_%H%M%S') + '.zip')
  11.  
  12. zip_command = 'zip -qr {0} {1}'.format(archive, ' '.join(sources))
  13.  
  14. if os.system(zip_command):
  15. print('Backup creating failed.')
  16. else:
  17. print('Backup was successfully created in', archive)
  18.  
  19. if __name__ == '__main__':
  20. sources = [
  21. os.path.expanduser('~/work'),
  22. os.path.expanduser('~/Keepass2'),
  23. ]
  24. bkp_folder = os.path.expanduser('~/Backups')
  25. backup(sources, bkp_folder)
  26.  
Runtime error #stdin #stdout #stderr 0.01s 9008KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 25, in <module>
  File "prog.py", line 8, in backup
TypeError: makedirs() got an unexpected keyword argument 'exist_ok'