Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ You can also specify the following options:
* --out-file: Log file for innobackupex output (default: */var/log/mysql/xtrabackup.out*).
* --backup-threads: You can specify more threads in order to backup quicker (default: 1).
* --no-compress: Do not compress the backup archive.
* --webhook: URL to send a POST request after the backup is finished. Will send the *archive_path* and *archive_repository* in JSON.

Restoration
-----------
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
docopt
docopt
requests
15 changes: 14 additions & 1 deletion xtrabackup/backup_tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from xtrabackup.command_executor import CommandExecutor
from xtrabackup.exception import ProcessError
from xtrabackup.http_manager import HttpManager
import xtrabackup.filesystem_utils as filesystem_utils
import xtrabackup.log_manager as log_manager
import xtrabackup.exception as exception
Expand All @@ -15,6 +16,7 @@ def __init__(self, log_file, output_file, no_compression):
self.setup_logging(log_file)
self.command_executor = CommandExecutor(output_file)
self.compress = not no_compression
self.http = HttpManager()

def setup_logging(self, log_file):
self.logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -146,6 +148,15 @@ def transfer_backup(self, repository):
def clean(self):
filesystem_utils.delete_directory_if_exists(self.workdir)

def trigger_webhook(self, webhook_url):
postdata = {
'archive_repository': self.backup_repository,
'archive_path': self.final_archive_path,
}
self.logger.debug("POST archive_repository: " + self.backup_repository)
self.logger.debug("POST archive_path: " + self.final_archive_path)
self.http.post(webhook_url, postdata)

def save_incremental_data(self, incremental):
try:
if incremental:
Expand Down Expand Up @@ -187,7 +198,7 @@ def load_incremental_data(self):
raise

def start_full_backup(self, repository, workdir, user,
password, threads):
password, threads, webhook):
self.check_prerequisites(repository)
self.prepare_workdir(workdir)
self.prepare_repository(repository, False)
Expand All @@ -197,6 +208,8 @@ def start_full_backup(self, repository, workdir, user,
self.archive_backup()
self.transfer_backup(repository)
self.clean()
if webhook:
self.trigger_webhook(webhook)

def start_incremental_backup(self, repository, incremental,
workdir, user, password, threads):
Expand Down
8 changes: 6 additions & 2 deletions xtrabackup/full_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
[--log-file=<log>] \
[--out-file=<log>] \
[--backup-threads=<threads>] \
[--no-compress]
[--no-compress] \
[--webhook=<url>]
pyxtrabackup (-h | --help)
pyxtrabackup --version

Expand All @@ -31,6 +32,8 @@
Threads count [default: 1].
--no-compress \
Do not create a compressed archive of the backup.
--webhook=<url> \
Webhook post backup. If enable will post backup information in JSON format.

"""
from docopt import docopt
Expand All @@ -48,7 +51,8 @@ def main():
arguments['--tmp-dir'],
arguments['--user'],
arguments['--password'],
arguments['--backup-threads'])
arguments['--backup-threads'],
arguments['--webhook'])
except Exception:
logger = logging.getLogger(__name__)
logger.error("pyxtrabackup failed.")
Expand Down
7 changes: 7 additions & 0 deletions xtrabackup/http_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import requests


class HttpManager:

def post(self, url, json):
requests.post(url, json=json)