zoukankan      html  css  js  c++  java
  • 一个简单的备份方案 (Linux Server to Windows Server)

    工作需要:备份 Linux server 的 subversion repo 到 Windows server.

    1) 在 Windows server 创建共享文件夹 Linux_Server_SVN_Backup_folder(注意设置必要的共享权限,不要设成 everyone)

    2) 在 Linux server 编写如下 Python 脚本 svn_backup.py,实现压缩和拷贝,

    #!/usr/bin/env python3
    # -*- coding: utf-8 -*-
    
    import os
    import time
    
    current_time = time.strftime('%Y-%m-%d_%H.%M.%S')                    # timestamp
    src_path_list = ['/svn']                                             # folder to backup
    dst_path = '/home/peterpan/SVN_backup_repo'                          # folder to store temp repo 7z package
    dst_file = dst_path + os.sep + 'SVN_backup_' + current_time + '.7z'  # 7z package name
    dst_log = dst_path + os.sep + 'svn_backup.log'                       # log file to record operation
    mount_path = '/mnt/windowsShare'                                     # folder to use mount Windows Share folder
    
    command_package_7z = '7za a %s %s' % (dst_file, ' '.join(src_path_list))  # Note, 7za is auto recursive, no need other options such as '-r'
    command_mount_win_share_folder = 'mount  -t  cifs  -o  user=peterpan,password=123456  //10.217.32.78/Linux_Server_SVN_Backup_Folder  /mnt/windowsShare/'
    command_cp_to_mount_folder = 'cp %s /mnt/windowsShare' % dst_file
    command_umount = 'umount /mnt/windowsShare'
    
    with open(dst_log, 'a') as fh_log:
        fh_log.write('============= %s =============
    ' % current_time)
        if os.system(command_package_7z) == 0:
            fh_log.write('%s
    ' % 'package to 7z succeed')
            if os.system(command_mount_win_share_folder) == 0:
                fh_log.write('%s
    ' % 'mount win share folder succeed')
                if os.system(command_cp_to_mount_folder) == 0:
                    fh_log.write('%s
    ' % 'cp package to mount folder succeed')
                    if os.system(command_umount) == 0:
                        fh_log.write('%s
    
    ' % 'umount succeed')
                    else:
                        fh_log.write('%s
    ' % 'umount failed')
                else:
                    fh_log.write('%s
    ' % 'cp package to mount folder failed')
            else:
                fh_log.write('%s
    ' % 'mount win share folder failed')
        else:
            fh_log.write('%s
    
    ' % 'package to 7z failed')

    并设置脚本执行权限,

    $ chmod a+x svn_backup.py

    3) 为上述脚本安排 crontab 排程

    因为上述脚本有些操作需要 root 权限,例如 mount,umount,所以为 root 用户安排 crontab 定时任务,

    $ su -
    # crontab -e

    默认打开 vi 编辑器,编辑内容如下,实现每周五的23点59分运行备份脚本,(注意开头的数字依次代表: 分,时,日,月,周)

    59  23  *  *  5  /home/peterpan/SVN_backup_repo/svn_backup.py

    保存退出,查看为 root 用户安排的 crontab 定时任务,

    # crontab -l

    如果要修改,则依然使用,

    # crontab -e

    如果要删除全部定时任务,则使用,

    # crontab -r

    完。

  • 相关阅读:
    C#判断是否运行在调试模式下
    [php] Interface abstract里面的私有方法 private method of interface and abstract class
    [html] Javascript warning and error of w3c
    [html] <a> and <input> can not click in IE6 when use png fixed IE6下png图片和png背景透明导致该区域的链接和按钮无效
    [Ubuntu] invalid environment block
    [Ubuntu] 分割与合并文件 Cut and mix the file
    [php] Treat an object like an array
    [eZ publish] How to add a element to an array.
    [html] PHP使用Google map web services来计算两点间的距离 Compute the distance between two place via Google map services in PHP
    [html] symbol of <b> and <strong>
  • 原文地址:https://www.cnblogs.com/gaowengang/p/12760001.html
Copyright © 2011-2022 走看看