Skip to content

Instantly share code, notes, and snippets.

@akionsight
Created January 3, 2021 05:52
Show Gist options
  • Save akionsight/cb47f2755ff2e8f1aed60b1dae3197e9 to your computer and use it in GitHub Desktop.
Save akionsight/cb47f2755ff2e8f1aed60b1dae3197e9 to your computer and use it in GitHub Desktop.
Auto backup a specific folder to a drive (external or internal)
import schedule
import os
os.system('pip install schedule')
# change this to your own drive (this drive acts as the backup drive)
DRIVE_LOCATION = 'D:\\'
# change this to the folder you want to backup (this folder will be backed up)
FOLDER_TO_BE_BACKED_UP = 'SOME_FOLDER'
# this will be the interval between backup's defualts to 10 seconds (change it to suit your needs)
BACKUP_FREQUNCY = 10
def backup_to_drive(DRIVE_LOCATION, FOLDER_TO_BE_BACKED_UP):
for i in os.listdir('lol'):
with open(FOLDER_TO_BE_BACKED_UP + i, 'r+') as file:
file_contents = file.read()
# print(file_contents)
with open(f"{DRIVE_LOCATION}{i}", 'w+') as file:
file.write(file_contents)
schedule.every(BACKUP_FREQUNCY).seconds.do(backup_to_drive)
while True:
schedule.run_pending()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment