gebos_backup.py 754 B

123456789101112131415161718192021222324252627
  1. import os
  2. from pathlib import Path
  3. def gebos_backup(base_dir=None):
  4. if base_dir is None:
  5. base_dir = 'E:\\GEBOS'
  6. source_path = Path(base_dir) / 'data'
  7. target_path = base_dir + '/archive'
  8. for source_file in source_path.glob('*.csv'):
  9. # print(source_file)
  10. table, timestamp = source_file.name.split('2', 1)
  11. timestamp = '2' + timestamp
  12. year = timestamp[:4]
  13. month = timestamp[4:6]
  14. target = Path(f"{target_path}/{year}/{table}/{year}-{month}/{source_file.name}").absolute()
  15. os.makedirs(target.parent, exist_ok=True)
  16. if target.exists():
  17. target.unlink()
  18. print(target)
  19. source_file.rename(target)
  20. if __name__ == '__main__':
  21. gebos_backup()