HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //lib/python2.7/site-packages/lap/mybackup.py
import ConfigParser
import MySQLdb
import os.path
import subprocess
import time


def __run__(params):
    conn = None

    # if gracetime, ignore the check
    now = time.localtime()
    gracetime = int(params.get('gracetime'))
    if now.tm_hour < gracetime:
        return [0, 'Backup em execucao - checagem livre das 0h as %dh' % gracetime]

    try:
        cp = ConfigParser.ConfigParser()
        cp.readfp(open("/etc/locaweb/mybackup/mybackup.conf"))
        timeout = 2

        conn = MySQLdb.connect(host=cp.get('mybackup', 'host'),
                user=cp.get('mybackup', 'user'),
                passwd=cp.get('mybackup', 'password'),
                db=cp.get('mybackup', 'dbname'),
                connect_timeout=timeout)
        cursor = conn.cursor()

        try:
            cursor.execute("""select count(1) 
                    from mybackup_catalog 
                    where created_at=date(now()) and db!='information_schema'""")
            total_db = cursor.fetchone()[0]
            if total_db == 0:
                return [2, 'CRITICAL: Catalogo de backup nao encontrado']
        except Exception, e:
                return [2, 'CRITICAL: Catalogo de backup nao encontrado']

        cursor.execute("""select count(1) 
                from mybackup_catalog 
                where (st_backup = 'ERROR' or st_backup is null) 
                and created_at=date(now()) and db!='information_schema'""")
        backup_count = cursor.fetchone()[0]

        cursor.execute("""select count(1) 
                from mybackup_catalog 
                where (st_compress = 'ERROR' or st_compress is null) 
                and created_at=date(now()) and db!='information_schema'""")
        tarfile_count = cursor.fetchone()[0]

        if (backup_count == 0 and tarfile_count == 0):
            return [0, 'OK: backup completed']

        # not completed, what happened?
        # running?

        # not sure if mybackup do the right thing with the pidfile
        if os.path.exists('/usr/sbin/lsof'):
            lsof_command = '/usr/sbin/lsof'
        elif os.path.exists('/usr/bin/lsof'):
            lsof_command = '/usr/bin/lsof'
        else:
            return [2, 'CRITICAL: lsof not found']

        devnull = open('/dev/null', 'rw')
        message = 'CRITICAL: Backup incompleto Total de Erros: %d'
        for p in ['mybackup', 'myinnodb']:
            lsof = subprocess.Popen([lsof_command, '/var/lock/{0}'.format(p)],
                    stdin=devnull, stdout=devnull, stderr=devnull)
            ret = lsof.wait()
            if ret == 0:
                message = 'CRITICAL: Backup incompleto Total de Erros: %d - backup ainda em execucao'
                break
        return [2, message % backup_count]

    except Exception, e:
        return [2, 'CRITICAL: {0}'.format(str(e))]
    finally:
        try:
            if conn:
                conn.close()
        except:
            # finally clause, don't bother about errors here
            pass