代码git每天自动备份到私有仓库

需求

很久就想搞了,每天写的代码晚上12点自动备份到github的私有仓库上去,这样就算电脑坏了或者换电脑了也不用管

  1. 00:00 git 自动push
  2. git commit -m 里面有时间信息,类似"auto push 2020 1009"

实现

写个shell

#! /bin/sh
#
# git_auto_push.sh
# Copyright (C) 2020 yons <yons@yons-Z390-AORUS-PRO>
#
# Distributed under terms of the MIT license.
#

git_push(){
    echo "start pushing"
    modify_time=`stat -c %Y ${1}`
    this_time=`date +%s`

    cd ${1}
    echo "-------change directory------"
    echo `pwd`
    echo "---------------------"
    date=`date "+%Y-%m-%d %H:%M:%S"`
    git add .    
    git commit -m "everyday automatic push $(date)"
    echo "git fetch origin master"
    git fetch origin master

    echo "git merge origin/master"
    git merge origin/master

    echo "git push origin master:master"
    git push origin master:master
}

git_push /home/yons/workplace/markdown

命名为auto_git_push.sh,当然前提是配好git的ssh,然后sh auto_git_push.sh测试一下能否正常push,应该没问题

加入定时任务

crontab -e,加入以下

# every 00:00
0 0 * * * /home/yons/workplace/shell/git_auto_push.sh

启动定时任务

sudo /etc/init.d/cron start

效果

在这里插入图片描述

macos

类似操作 [refer](https://stackoverflow.com/questions/51722335/how-to-run-shell-script-daily-in-mac-os-x/51722471_

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值