【问题标题】:Mariabackup ignoring --target-dirMariabackup 忽略 --target-dir
【发布时间】:2019-07-28 16:39:49
【问题描述】:

我正在将我们的 mariadb 备份作业自动化到 python 程序中。但是由于某种原因,似乎 --target-directory 参数虽然被正确传递并通过打印验证,但在从 os.system 运行实际命令时被忽略。代码如下:

import os
import datetime, time
import mysql.connector as mariadb


unix_socket = "/var/lib/mysql/mysql.sock"
currentdate = datetime.datetime.now()
bkp_path = time.strftime("/%Y/%m-%d/%H%M")
ro_status = ("show global variables like 'read_only%'")
dblist = ("show databases")
db = mariadb.connect(user='pytest', password='pytest', unix_socket=unix_socket)
cur = db.cursor()
cur.execute(ro_status)
result = cur.fetchall()
for r in result:
        if "OFF" in r:
            cur.execute(dblist)
            dbs = cur.fetchall()
            for d in dbs:
                dbstr = ''.join(d)
                bkp_path = "/backups/" + dbstr + time.strftime("/%Y/%m-%d/%H%M/")
                bkp_cmd = "sudo mariabackup --backup --databases='" + dbstr + "' --target-directory=" + bkp_path +"  --user pytest --password=pytest --no-lock"
                try:
                    os.stat(bkp_path)
                except:
                    os.makedirs(bkp_path)
                try:
                   # print(bkp_cmd)
                    os.system(bkp_cmd)
                except:
                        print("Problem running backup on this host")
        else:
            print(h + " is read only and will not be backed up")

打印命令示例: sudo mariabackup --backup --databases="testdbBA" --target-directory=/backups/testdbBA/2019/03-06/1659/ --user pytest --password=pytest --no-lock

即使通过打印块单独运行 - 它也会尝试写入我的本地主目录而不是指定的目标目录。

【问题讨论】:

标签: python mariadb mysql-python


【解决方案1】:

它的 --target-dir 不是 --target-directory

感谢 MFisherKDX

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-21
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-14
    相关资源
    最近更新 更多