forked from drakkan/sftpgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Data Backup | ||
|
||
The `backup` example script shows how to use the SFTPGo REST API to backup your data. | ||
|
||
The script is written in Python and has the following requirements: | ||
|
||
- python3 or python2 | ||
- python [Requests](https://requests.readthedocs.io/en/master/) module | ||
|
||
The provided example tries to connect to an SFTPGo instance running on `127.0.0.1:8080` using the following credentials: | ||
|
||
- username: `admin` | ||
- password: `password` | ||
|
||
and, if you execute it daily, it saves a different backup file for each day of the week. The backups will be saved within the configured `backups_path`. | ||
|
||
Please edit the script according to your needs. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python | ||
|
||
from datetime import datetime | ||
import sys | ||
|
||
import requests | ||
|
||
try: | ||
import urllib.parse as urlparse | ||
except ImportError: | ||
import urlparse | ||
|
||
# change base_url to point to your SFTPGo installation | ||
base_url = "http://127.0.0.1:8080" | ||
# set to False if you want to skip TLS certificate validation | ||
verify_tls_cert = True | ||
# set the credentials for a valid admin here | ||
admin_user = "admin" | ||
admin_password = "password" | ||
|
||
# get a JWT token | ||
auth = requests.auth.HTTPBasicAuth(admin_user, admin_password) | ||
r = requests.get(urlparse.urljoin(base_url, "api/v2/token"), auth=auth, verify=verify_tls_cert, timeout=10) | ||
if r.status_code != 200: | ||
print("error getting access token: {}".format(r.text)) | ||
sys.exit(1) | ||
access_token = r.json()["access_token"] | ||
auth_header = {"Authorization": "Bearer " + access_token} | ||
|
||
r = requests.get(urlparse.urljoin(base_url, "api/v2/dumpdata"), | ||
params={"output-file":"backup_{}.json".format(datetime.today().strftime('%w'))}, | ||
headers=auth_header, verify=verify_tls_cert, timeout=10) | ||
if r.status_code == 200: | ||
print("backup OK") | ||
else: | ||
print("backup error, status {}, response: {}".format(r.status_code, r.text)) |