Python backup script

12 Mar 2019 Script #python #craftserve

Some time ago I created a little script to automate backups from my server.

It requires Python 3.x with requests installed (pip install requests)

import requests, shutil, datetime

# Configuration.

mail = '[email protected]'
password = 'password'
sid = '602959'
folder = 'world'

# Code.

fileName ="%Y-%m-%d-%H-%M-%S") + '.zip'
s = requests.session()
login = {'email': mail, 'password': password, 'send': ''} 
r ='', login)

r = s.get('' + sid + '/files/' + folder + '?zip=1', stream=True)
with open(fileName, 'wb') as f:
    shutil.copyfileobj(r.raw, f)

You can extend it by adding Discord notifications, uploading files to cloud or sending commands to console, for example:'' + sid + '/console', 'save-off')