<commit_before>#!/usr/bin/python
"""
Usage: xtrabackup_send.py <hostname>
Author: Matthieu 'Korrigan' Rosinski <<EMAIL>>

This script runs xtrabackup and pipe the output to <hostname>


"""
import os
import sys

import subprocess
import argparse


opts = None


def main():
    """
    Main entry point for xtrabackup_send

    """
    global opts

    parser = argparse.ArgumentParser(
        description='This program is a wrapper for sending xtrabackup to a target over SSH',
        epilog='Copyright Quanta-computing 2014',
        )
    parser.add_argument('-u', '--user', help='Specifies the remote user to use for SSH auth')
    parser.add_argument('-k', '--ssh-key', help='Specified a custom ssh key to use')
    parser.add_argument('-d', '--debug', action='store_true', help='Show the stdout/stderr of the processes')
    parser.add_argument('host', help='The remote hostname or IP address')
    opts = parser.parse_args()
    send_backup(opts.host)


def send_backup(host):
    """
    Executes innobackupex and pipe it trough gzip and ssh

    """
    null = None
    if not opts.debug:
        null = open('/dev/null', 'w')
    ssh_host = host
    ssh_key = []
    if opts.user:
        ssh_host = "{}@{}".format(opts.user, ssh_host)
    if opts.ssh_key:
        ssh_key = ['-i', opts.ssh_key]
    ssh = subprocess.Popen(['ssh', ssh_host] + ssh_key,
                           stdin=subprocess.PIPE,
                           stdout=null,
                           stderr=null)
    gzip = subprocess.Popen(['gzip', '-q', '-c', '-'],
                            stdin=subprocess.PIPE,
                            stdout=ssh.stdin,
                            stderr=null)
    xtrabackup = subprocess.Popen(['innobackupex', '--stream=tar', '/tmp'],
                                  stdout=gzip.stdin,
                                  stderr=null)
    xtrabackup.wait()
    gzip.stdin.close()
    gzip.wait()
    ssh.stdin.close()
    ssh.wait()
    sys.exit(gzip.returncode + ssh.returncode + xtrabackup.returncode)


if __name__ == "__main__":
    main()<commit_msg>added mongo option to suprabackup-send<commit_after>#!/usr/bin/python
"""
Usage: xtrabackup_send.py <hostname>
Author: Matthieu 'Korrigan' Rosinski <<EMAIL>>

This script runs xtrabackup and pipe the output to <hostname>


"""
import os
import sys

import subprocess
import argparse


opts = None


def main():
    """
    Main entry point for xtrabackup_send

    """
    global opts

    parser = argparse.ArgumentParser(
        description='This program is a wrapper for sending xtrabackup to a target over SSH',
        epilog='Copyright Quanta-computing 2014',
        )
    parser.add_argument('-u', '--user', help='Specifies the remote user to use for SSH auth')
    parser.add_argument('-k', '--ssh-key', help='Specified a custom ssh key to use')
    parser.add_argument('-t', '--type', help='The type of the backup to perform',
                        choices=['mysql', 'mongo'], default='mysql')
    parser.add_argument('-d', '--debug', action='store_true',
                        help='Show the stdout/stderr of the processes')
    parser.add_argument('host', help='The remote hostname or IP address')
    opts = parser.parse_args()
    send_backup(opts.host)


def send_backup(host):
    """
    Executes innobackupex and pipe it trough gzip and ssh

    """
    null = None
    if not opts.debug:
        null = open('/dev/null', 'w')
    ssh_host = host
    ssh_key = []
    if opts.user:
        ssh_host = "{}@{}".format(opts.user, ssh_host)
    if opts.ssh_key:
        ssh_key = ['-i', opts.ssh_key]
    ssh = subprocess.Popen(['ssh', ssh_host] + ssh_key,
                           stdin=subprocess.PIPE,
                           stdout=null,
                           stderr=null)
    gzip = subprocess.Popen(['gzip', '-q', '-c', '-'],
                            stdin=subprocess.PIPE,
                            stdout=ssh.stdin,
                            stderr=null)
    if opts.type == 'mysql':
        command = ['innobackupex', '--stream=tar', '/tmp']
    else:
        command = ['mongodump', '--archive']
    xtrabackup = subprocess.Popen(command, stdout=gzip.stdin, stderr=null)
    xtrabackup.wait()
    gzip.stdin.close()
    gzip.wait()
    ssh.stdin.close()
    ssh.wait()
    sys.exit(gzip.returncode + ssh.returncode + xtrabackup.returncode)


if __name__ == "__main__":
    main()
{'fraction_non_alphanumeric': 0.13225952813067152, 'fraction_numerical': 0.0018148820326678765, 'mean_word_length': 2.2538745387453876, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6511152', 'n_tokens_mistral': 1468, 'n_tokens_neox': 1383, 'n_words': 342}