Add backup action
Add a new action to backup the pxc database on a unit. Backups by default are stored in /opt/backups/mysql and can optionally be compressed and done as incremental backups. Change-Id: I5c6ab9fd8be7cb6cdb2a26e849ec0b22d8d4f9a6
This commit is contained in:
parent
5cf419bdbb
commit
2bc5d6e2f9
18
actions.yaml
18
actions.yaml
|
@ -1,4 +1,20 @@
|
|||
pause:
|
||||
description: Pause the MySQL service.
|
||||
resume:
|
||||
description: Resume the MySQL service.
|
||||
description: Resume the MySQL service.
|
||||
backup:
|
||||
description: Full database backup
|
||||
params:
|
||||
basedir:
|
||||
type: string
|
||||
default: "/opt/backups/mysql"
|
||||
description: The base directory for backups
|
||||
compress:
|
||||
type: boolean
|
||||
default: false
|
||||
description: Whether or not to compress the backup
|
||||
incremental:
|
||||
type: boolean
|
||||
default: false
|
||||
description: Make an incremental database backup
|
||||
|
||||
|
|
|
@ -2,11 +2,20 @@
|
|||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import traceback
|
||||
from time import gmtime, strftime
|
||||
|
||||
from charmhelpers.core.host import service_pause, service_resume
|
||||
from charmhelpers.core.hookenv import action_fail, status_set
|
||||
from percona_utils import assess_status
|
||||
from charmhelpers.core.hookenv import (
|
||||
action_get,
|
||||
action_set,
|
||||
action_fail,
|
||||
status_set,
|
||||
config,
|
||||
)
|
||||
|
||||
from percona_utils import assess_status
|
||||
|
||||
MYSQL_SERVICE = "mysql"
|
||||
|
||||
|
@ -32,9 +41,45 @@ def resume(args):
|
|||
assess_status()
|
||||
|
||||
|
||||
def backup():
|
||||
basedir = (action_get("basedir")).lower()
|
||||
compress = (action_get("compress"))
|
||||
incremental = (action_get("incremental"))
|
||||
sstpw = config("sst-password")
|
||||
optionlist = []
|
||||
|
||||
# innobackupex will not create recursive dirs that do not already exist,
|
||||
# so help it along
|
||||
if not os.path.exists(basedir):
|
||||
os.makedirs(basedir)
|
||||
|
||||
# Build a list of options to pass to innobackupex
|
||||
if compress is "true":
|
||||
optionlist.append("--compress")
|
||||
|
||||
if incremental is "true":
|
||||
optionlist.append("--incremental")
|
||||
|
||||
try:
|
||||
subprocess.check_call(
|
||||
['innobackupex', '--compact', '--galera-info', '--rsync',
|
||||
basedir, '--user=sstuser', '--password=' + sstpw] + optionlist)
|
||||
action_set({
|
||||
'time-completed': (strftime("%Y-%m-%d %H:%M:%S", gmtime())),
|
||||
'outcome': 'Success'}
|
||||
)
|
||||
except subprocess.CalledProcessError as e:
|
||||
action_set({
|
||||
'time-completed': (strftime("%Y-%m-%d %H:%M:%S", gmtime())),
|
||||
'output': e.output,
|
||||
'return-code': e.returncode,
|
||||
'traceback': traceback.format_exc()})
|
||||
action_fail("innobackupex failed, you should log on to the unit"
|
||||
"and check the status of the database")
|
||||
|
||||
# A dictionary of all the defined actions to callables (which take
|
||||
# parsed arguments).
|
||||
ACTIONS = {"pause": pause, "resume": resume}
|
||||
ACTIONS = {"pause": pause, "resume": resume, "backup": backup}
|
||||
|
||||
|
||||
def main(args):
|
||||
|
|
Loading…
Reference in New Issue