diff options
author | Lan Hui <lanhui@zjnu.edu.cn> | 2025-04-20 18:50:52 +0800 |
---|---|---|
committer | Lan Hui <lanhui@zjnu.edu.cn> | 2025-04-20 18:50:52 +0800 |
commit | 15354cbf37cee332efe819aec3fe988b5133d769 (patch) | |
tree | 6a4b8a8b9e3c37a2191d494e2f83755574d175c9 /Code/backup_files.py | |
parent | ceaaaa4c1ced17be4aefef1f6ee4a77f39b95726 (diff) |
Backup old RNA_SEQ_INFO_DATABASE_JSON and replace it with an updated one
Diffstat (limited to 'Code/backup_files.py')
-rw-r--r-- | Code/backup_files.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Code/backup_files.py b/Code/backup_files.py index 1ab3fab..4984a66 100644 --- a/Code/backup_files.py +++ b/Code/backup_files.py @@ -7,6 +7,7 @@ # Created on 7 December 2019 by Hui Lan (lanhui@zjnu.edu.cn) import os, sys +import gzip from configure import UPDATE_NETWORK_LOG_FILE from datetime import datetime from log import write_log_file @@ -34,6 +35,16 @@ def copy_and_backup_file(src_file, dest_dir): write_log_file('[backup_files.py] File %s has been backed up to %s and zipped (.gz)' % (src_file, dest_file), UPDATE_NETWORK_LOG_FILE) +def backup_file(src_file): + if not os.path.exists(src_file): + raise Exception(f'{src_file} does not exists.') + curr_date = datetime.now().strftime('%Y%m%d') + zip_fname = src_file + '.' + curr_date + '.gz' + with gzip.open(zip_fname, 'wb') as gz: + with open(src_file) as f: + gz.write(f.read().encode('utf-8')) + return zip_fname + ## main if __name__ == '__main__': copy_and_backup_file('../Data/temp/edges.txt', '../Analysis') |