Created
April 7, 2018 17:12
-
-
Save DisasteR/336096575caf3ba73b3bcae34a673435 to your computer and use it in GitHub Desktop.
Bluemind Run Backup Script for backuppc DumpPreUserCmd
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
# You need to install python-bm-client or netbluemind using pip to run this script | |
import requests | |
import sys | |
import time | |
import datetime | |
try: | |
from requests.packages.urllib3.exceptions import InsecureRequestWarning | |
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) | |
except ImportError: | |
pass | |
from netbluemind.python.client import BMClient | |
from netbluemind.dataprotect.api.IDataProtect import IDataProtect | |
from netbluemind.core.task.api.TaskRef import TaskRef | |
from netbluemind.core.task.api.TaskStatusState import TaskStatusState | |
from netbluemind.core.task.api.ITask import ITask | |
# BEGIN CONF | |
URL="http://localhost:8090/api" | |
# END CONF | |
if len(sys.argv) != 1: | |
print "Usage : ./bm-runbackup.py" | |
sys.exit(1) | |
print "Running BlueMind Backup" | |
f = open('/etc/bm/bm-core.tok', 'r') | |
KEY = f.readline() | |
f.close() | |
client = BMClient(URL, KEY) | |
idataprotect = client.instance(IDataProtect) | |
start = datetime.datetime.now() | |
taskRef = idataprotect.saveAll() | |
itask = client.instance(ITask, taskRef.id) | |
print "-- JobUID : " + taskRef.id | |
status = itask.status() | |
sys.stdout.write('.') | |
sys.stdout.flush() | |
while status.state == TaskStatusState.InProgress or status.state == TaskStatusState.NotStarted: | |
time.sleep(10) | |
sys.stdout.write('.') | |
sys.stdout.flush() | |
status = itask.status() | |
sys.stdout.write('\n') | |
end = datetime.datetime.now() | |
for line in itask.getCurrentLogs(): | |
print "-- JobLOG : " + line.encode('utf-8') | |
print "Backup done with status [" + status.state.value + "] in " + str(end - start) | |
if status.state == TaskStatusState.InError: | |
sys.exit(1) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example output :