下面的代码都是newlisp, 在crontab的帮助下实现定时备份git仓库和mysql数据库。因为git lab的数据存放在这里。
事实上,newlisp很适合做运维脚本。
git_backup.lsp文件:
(set ‘folder-name (date (date-value) 0 “%Y-%m-%d”))
(println folder-name)
(set ‘folder-name2 (date (date-value) -2880 “%Y-%m-%d”))
(set ‘base-path “/opt/shareOn110/bk/git/”)
(println folder-name2)
(make-dir (append base-path folder-name))
(exec (append “cp -r /home/git/repositories ” base-path folder-name))
(if (file? (append base-path folder-name2))
(exec (append “rm -rf ” base-path folder-name2)))
(exit)
mysql_backup.lsp文件:
File Edit Options Buffers Tools Lisp Help
(set ‘folder-name (date (date-value) 0 “%Y-%m-%d”))
(println folder-name)
(set ‘folder-name2 (date (date-value) -2880 “%Y-%m-%d”))
(set ‘base-path “/opt/shareOn110/bk/mysql/”)
(println folder-name2)
(make-dir (append base-path folder-name))
(exec (append “mysqldump -u root -pyour_pwd –all-databases > ” base-path folder-name “/all-database.sql”))
(if (file? (append base-path folder-name2))
(exec (append “rm -rf ” base-path folder-name2)))
(exit)
注意,由于newlisp文件操作的API中不能让人很轻松的复制目录,所以这里还用到了linux命令cp -r
以后考虑自己写一个。或者等待lutz增加这个API?
crontab的配置:
50 23 * * * newlisp /opt/git_backup.lsp
40 23 * * * newlisp /opt/mysql_backup.lsp
前提是Ubuntu系统里面已经安装了newlisp。
GitLab 的详细介绍:请点这里
GitLab 的下载地址:请点这里