三月阳光 发表于 2015-11-10 14:12:33

newlisp 备份mongodb数据库

  
#!/usr/bin/newlisp
(set 'folder-name (date (date-value) 0 "%Y-%m-%d"))
(set 'base-path "/opt/backup")
(set 'mongo-host "192.168.1.51")
(set 'save-dir (format "%s/%s" base-path folder-name))
(set 'del-cmd (format "rm -rf %s" save-dir))
(if (file? save-dir) (exec del-cmd))
(make-dir save-dir)
(set 'back-cmd (format "mongodump --host %s -d test_db -o %s/%s" mongo-host base-path folder-name))
(exec back-cmd)
(set 'del-dir (date (date-value) -2880 "%Y-%m-%d"))
(set 'del-cmd (format "rm -rf %s" del-dir))
(if (file? save-dir) (exec del-cmd))
(exit)

每次都会删除前天的备份数据。  
  

   
版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: newlisp 备份mongodb数据库