美文网首页
linux 定时备份文件到 Gitlab

linux 定时备份文件到 Gitlab

作者: _浅墨_ | 来源:发表于2018-05-15 15:22 被阅读32次

    需求:现在需要将 Sqlite 目录下面的 showdoc.db.php 数据库文件备份到gitlab,以防止本地服务器上面该文件意外丢失。

    目录

    解决方案:在 /var/www/html/showdoc 目录下新建 uploadDB 目录,该目录绑定 gitlab 项目。

    实现步骤:

    1. 在 /var/www/html/showdoc/Sqlite 下新建文件 update.sh,内容为:
    cp /var/www/html/showdoc/Sqlite/showdoc.db.php /var/www/html/showdoc/uploadDB/showdoc/showdoc.db.php
    
    1. 在 /var/www/html/showdoc/uploadDB/showdoc/ 下新建 autopush.sh 文件,内容为:
    git add .
    git commit -m “update showdoc db”
    git push origin master
    
    1. 命令行编辑 crontab,键入:
      crontab -e

    2. 添加 sh 命令到定时任务

    50 23 * * * /bin/sh /var/www/html/showdoc/Sqlite/update.sh
    59 23 * * * /bin/sh /var/www/html/showdoc/uploadDB/showdoc/autopush.sh
    
    1. 重启 crontab 服务
      /sbin/service crond restart

    附:crontab 常用命令:

    重新指定 crontab 定时任务列表文件
    crontab $filepath
    
    查看 crontab 定时任务
    crontab -l
    
    编辑定时任务【删除-添加-修改】
    crontab -e
    
    要判定该软件包是否已安装,使用 rpm -q vixie-cron 命令。
    要判定该服务是否在运行,使用 /sbin/service crond status 命令。
    
    加入开机自动启动:
    chkconfig –level 35 crond on
    
    服务操作说明:
    /sbin/service crond start// 启动服务
    /sbin/service crond stop// 关闭服务
    /sbin/service crond restart// 重启服务
    /sbin/service crond reload// 重新载入配置
    /sbin/service crond status// 启动服务
    
    

    参考:

    1. Linux定时任务Crontab命令详解 - 再見理想 - 博客园
    2. 每天一个linux命令(50):crontab命令 - peida - 博客园
    3. crontab 定时任务 — Linux Tools Quick Tutorial
    4. Linux之crontab定时任务 - 简书

    相关文章

      网友评论

          本文标题:linux 定时备份文件到 Gitlab

          本文链接:https://www.haomeiwen.com/subject/xvzedftx.html