Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import schedule
- import sqlite3
- import subprocess
- import os
- import time
- import re
- sdrive = "/mnt/source"
- ddrive = "rclone_enc:/"
- servicefile = "XXXXXXXXX.iam.gserviceaccount.com.json"
- service = 1
- con = sqlite3.connect('./rclone.db', timeout=20)
- cursorObj = con.cursor()
- cursorObj.execute("CREATE TABLE IF NOT EXISTS serviceaccount(id integer PRIMARY KEY, current integer)")
- con.commit()
- cursorObj = con.cursor()
- cursorObj.execute('SELECT * FROM serviceaccount WHERE id = 1')
- rows = cursorObj.fetchall()
- if len(rows) == 0:
- cursorObj.execute("INSERT INTO serviceaccount (current) VALUES (1);")
- service = 1
- else:
- service = int(rows[0][1])
- def job():
- print("starting")
- global service, servicefile
- serviceaccount = "--drive-service-account-file=/home/gc2/keys/service" + str(service) + "@" + servicefile
- print( serviceaccount )
- print( "found enough files, syncing")
- process = subprocess.Popen(['rclone','sync', sdrive , ddrive ,'--drive-server-side-across-configs','--tpslimit=30','--transfers=4','--checkers=10', '--fast-list',
- '-c','--verbose=1','--stats=60s' , '--drive-stop-on-upload-limit','--max-backlog','10000','--exclude','**/.backups/**', serviceaccount],
- stdout=subprocess.PIPE,
- universal_newlines=True,
- shell=False,
- stderr=subprocess.STDOUT
- )
- while True:
- output = process.stdout.readline()
- if output.strip() != "":
- print(output.strip())
- return_code = process.poll()
- if return_code is 7:
- service += 1
- if service is 101:
- #exit()
- service = 1
- con = sqlite3.connect('./rclone.db', timeout=20)
- cursorObj = con.cursor()
- cursorObj.execute('UPDATE serviceaccount SET current = ' + str(service) + ' WHERE id = 1;')
- con.commit()
- con.close()
- schedule.every(1).minutes.do(job)
- return schedule.CancelJob
- if return_code is not None:
- if return_code is 0:
- schedule.every(120).minutes.do(job)
- print("** job done")
- return schedule.CancelJob
- print('RETURN CODE', return_code)
- # Process has finished, read rest of the output
- for output in process.stdout.readlines():
- print(output.strip())
- break
- schedule.every(120).minutes.do(job)
- return schedule.CancelJob
- schedule.every(1).seconds.do(job)
- while True:
- schedule.run_pending()
- time.sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment