Created
October 26, 2020 19:11
-
-
Save stripedpurple/a99f5fecd18d41a864bc22f0e50cff79 to your computer and use it in GitHub Desktop.
Rclone automation script for Mazz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import os | |
import errno | |
import datetime | |
import logging as log # Imported as log for ease of use | |
log_format = '%(asctime)s\t[%(levelname)s]\t%(message)s' | |
log.basicConfig(level=log.INFO, format=log_format, filename=os.path.basename(__file__) + '.log') | |
def backup_google_drive(user): | |
log.info('Beging backup of ' + user.name + " to " + path) | |
command = list(['rclone', 'copy', user.drive + ':' + '/' + user.path]) | |
try: | |
cmd = subprocess.run(command, capture_output=true, text=true) | |
except OSError as e: | |
log.error(e) | |
raise | |
except: | |
log.error('Something went wrong') | |
finally: | |
log.info(cmd.stdout) | |
log.info('Completed backup for ' + user.name) | |
def main(): | |
users = list([ | |
{ | |
'name': 'MathewRDangle', | |
'drive': 'Matthew Google Drive' | |
}, | |
{ | |
'name': 'MichelleSGalvez', | |
'drive': 'Michelle Google Drive' | |
}, | |
]) | |
for user in users: | |
log.info("Intitalizing backup for " + user['name']) | |
current_date = datetime.datetime.now().strftime("%Y-%m-%d-%H%M%S") | |
folder = "Backup-" + current_date | |
user["path"] = "/media/usb-drive/" + user['name'] + "/" + folder | |
log.info('Creating backup dirtectory: ' + user['path']) | |
try: | |
os.makedirs(user['path']) | |
except OSError as e: | |
if e.errno != errno.EEXIST: | |
log.error(e) | |
raise | |
backup_google_drive(user) | |
if __name__ == "__main__": | |
# execute only if run as a script | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment