Esempio n. 1
0
def job():
    logger.debug(datetime.datetime.now())
    backend = LocalBackend('/data/release/backup/')
    with YunBK('ybk', [backend]) as ybk:
        f = open('t2.txt', 'w')
        f.write('ok')
        f.close()
        ybk.backup()
Esempio n. 2
0
def backup():
    logger.debug(datetime.datetime.now())
    backend = LocalBackend('/data/release/backup/')
    with YunBK('ybk', [backend]) as ybk:
        with open('t.txt', 'w') as f:
            f.write('ok')

        ybk.backup()
Esempio n. 3
0
# -*- coding: utf-8 -*-

from yunbk import YunBK
from yunbk.backend.local import LocalBackend

import sh

backend = LocalBackend('/data/backup')

with YunBK('mysql', [backend]) as ybk:
    sh.mysqldump(u='root',
                 all_databases=True,
                 _out="dump.sql")
    ybk.backup()
Esempio n. 4
0
import sh
import shutil
import logging

KEEPS_APP = dict(
    months=7,
    weeks=2,
    days=4,
    seconds=3600 * 24,
)

logger = logging.getLogger('yunbk')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)

backend = LocalBackend('/data/backup', keeps=KEEPS_NORMAL)
# 这种写法将会以KEEPS_APP为准
# 如果KEEPS为None,将会以backend中的keeps为准
with YunBK('yb', [backend], keeps=KEEPS_APP) as ybk:
    # 生成文件
    with open('t.txt', 'w') as f:
        f.write('ok')

    # 备份文件
    shutil.copy('/data/store/db.sqlite3', 'db.sqlite3')

    # 备份目录,如redis
    shutil.copytree('/data/store/redis', 'redis')

    # 备份mysql所有库
    sh.mysqldump(u='root', all_databases=True, _out="dump_all.sql")
Esempio n. 5
0
#encoding:utf-8
# -*- coding: utf-8 -*-

from yunbk import YunBK
from yunbk.backend.local import LocalBackend
from yunbk.constants import KEEPS_NORMAL
import sh
import shutil
import logging
logger = logging.getLogger('yunbk')
logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)
backend = LocalBackend('/backup')
with YunBK('yb', [backend], keeps=KEEPS_NORMAL) as ybk:
    # 生成文件
    with open('t.txt', 'w') as f:
        f.write('ok')
    sh.mongodump(
        u='',
        p='',
        h='192.168.0.21',
        port=27017,
        d='admin',  # 不传-d参数即备份所有库
        o='mongo_dump',
    )

    ybk.backup()