关于工作,学习中定时备份的几个方法(cron,git,mail)
2015-12-29 14:56
627 查看
首先介绍一下cron这个定时备份的工具:
crontab -e : 执行文字编辑器来设定时程表,内定的文字编辑器是 VI,如果你想用别的文字编辑器,则请先设定 VISUAL 环境变数来指定使用那个文字编辑器(比如说 setenv VISUAL joe)crontab -r : 删除目前的时程表
crontab -l : 列出目前的时程表
crontab file [-u user]-用指定的文件替代目前的crontab。
时程表的格式如下 :
f1 f2 f3 f4 f5 program
其中 f1 是表示分钟,f2 表示小时,f3 表示一个月份中的第几日,f4 表示月份,f5 表示一个星期中的第几天。program 表示要执行的程序。
当 f1 为 * 时表示每分钟都要执行 program,f2 为 * 时表示每小时都要执行程序,其余类推
当 f1 为 a-b 时表示从第 a 分钟到第 b 分钟这段时间内要执行,f2 为 a-b 时表示从第 a 到第 b 小时都要执行,其余类推
当 f1 为 */n 时表示每 n 分钟个时间间隔执行一次,f2 为 */n 表示每 n 小时个时间间隔执行一次,其余类推
当 f1 为 a, b, c,... 时表示第 a, b, c,... 分钟要执行,f2 为 a, b, c,... 时表示第 a, b, c...个小时要执行,其余类推
使用者也可以将所有的设定先存放在档案 file 中,用 crontab file 的方式来设定时程表。
再介绍一下git这个很man工具:
git有2种方式提交,下载,一种是http,一种是ssh这里只介绍下不需要输入帐号密码应该怎么做:
ssh的话,一般会有个ssh key,把你的key复制到github上去即可,就是密钥,远程不需要输入密码
另一种http的方式则 git config --global credential.helper store 长期记住密码
这是为了方便定时自动提交,至于其他的操作读者自行百度
最后通过Mail提交小附件也不错:
用mutt发邮件: echo "`date`" |mutt -s "WorkBack" xxx@gmail.com -a filesfiles为附件,附件可以用tar打包,这只适合打包代码备份,太大发不出去.
也可以直接配好msmtp,用mail发邮件.
mutt的配置见 http://blog.csdn.net/lunaw/article/details/46853947
打造定时备份:
假如你需要每天下午5点20的时候备份几个目录
crontab可以这样写:
[html]
view plaincopy
# m h dom mon dow command
20 17 * * * /home/qx/xiaojunyu/temp/back.sh</span>
back.sh可以这样写:
[html]
view plaincopy
#!/bin/bash
# *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
# > Author: xiaojunyu/LunaW
# > Mail : xiaojunyu5201314@163.com
# > Gmail : lunaw.org@gmail.com
# > Blog : http://blog.csdn.net/lunaw
# > GitHub: https://github.com/lunaw
# > Web : http://lunaw.org http://lunaw.net
# *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
cd /home/qx/xiaojunyu/work
echo "`date`" >> README.md
git pull origin master ;git add -A ;git commit -m "`date`" ;git push origin master
cd /home/qx/xiaojunyu/temp
echo "`date`" >> README.md
git pull origin master ;git add -A ;git commit -m "`date`" ;git push origin master
cd /home/qx/xiaojunyu/
tar -zcvf work.tar.gz work/
#tar -zcvf temp.tar.gz temp/
date '+%Y-%m-%d' | mutt -s Work_backup sd17@fastnet.net.cn -a work.tar.gz
date '+%Y-%m-%d'| mutt -s Work_backup xiaojunyu5201314@qq.com -a work.tar.gz
rm -f work.tar.gz
只是很简单的顺着备份,没有写很复杂的功能,推荐git的方式,mail当作一个小备份,git可以根据整个目录的改动情况进行提交,比较节约资源
当然,还有很多用途,这只是冰山一角
相关文章推荐
- 打造终端下mutt收发邮件环境(fbterm,fetchmail,msmtp,procmail,mutt)
- 3D空间中的AABB(轴向平行包围盒, Aixe align bounding box)的求法
- Custom Container View Controller容器vc
- http://blog.csdn.net/techbirds_bao/article/details/9233599
- 最新Google Gmail邮箱登陆不了解决方法(hosts更新于12月14日)
- There is no public key available for the following key IDs:9D6D8F6BC857C906
- ssh中断“Write failed: Broken pipe”分析
- NSBundle的使用,注意mainBundle和Custom Bundle的区别
- POJ 1090 Chain
- Manage Data in Containers
- [__NSCFString containsString:]: unrecognized selector sent to instance 0x17d68490
- Networking Containers
- WM_PAINT介绍及OnPaint()函数的作用原理
- LeetCode 070 Climbing Stairs
- Hello world in a container
- RAID10与RAID01
- FZU 2216——The Longest Straight——————【二分、枚举】
- RAID Adapter and HBA Adapter
- sendmail
- NSString,NSMutableString使用retain, copy理解