yaks-backup.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python
  2. ################################################################################
  3. # FILE : yaks-backup.py
  4. # DESCRIPTION: A backup script for my system.
  5. # AUTHOR : SVAKSHA, http://svaksha.com/pages/Bio
  6. # SOURCE : http://svaksha.github.io/yaksha
  7. # COPYRIGHT© : 2005-Now SVAKSHA, All Rights Reserved.
  8. # LICENSE : GNU AGPLv3 and subject to meeting all the terms in the LICENSE
  9. # file: https://github.com/svaksha/yaksha/blob/master/LICENSE.md
  10. # DATES : Created:2015sep21 - Updated:2016jan14
  11. ################################################################################
  12. #
  13. import attic
  14. import rotate-backups
  15. import datetime
  16. import logging
  17. import os
  18. import shutil # https://docs.python.org/3/library/shutil.html
  19. LOCAL_BACKUP_DIR = '$HOME/2015-09-28-VID_{0}'
  20. def get_backup_directory(base_directory):
  21. date = str(datetime.datetime.now())[:16]
  22. date = date.replace(' ', '_').replace(':', '')
  23. return base_directory.format(date)
  24. def copy_files(directory):
  25. for file in os.listdir(LOCAL_BACKUP_DIR ):
  26. file_path = os.path.join(LOCAL_BACKUP_DIR , file)
  27. if os.path.isfile(file_path):
  28. shutil.copy(file_path, directory)
  29. def perform_backup(base_directory):
  30. backup_directory = get_backup_directory(base_directory)
  31. os.makedirs(backup_directory)
  32. copy_files(backup_directory)
  33. def main():
  34. perform_backup(LOCAL_BACKUP_DIR)
  35. if __name__ == '__main__':
  36. main()