如果我想在Linux VPS上压缩(或者tar.gz)一系列path(recursion地),然后将ZIP / TAR发送给我自己,然后删除ZIP / TAR,那么最简单的方法是什么? 一个cron作业,一个程序等的shell脚本?
例如,这是我可能做的事情:
停止apache,mysql,postgresql和rack
拉链拉上:
/etc/httpd/conf/httpd.conf /etc/httpd/conf.d/* /home/kerrick/* /var/lib/mysql/* # etc.
通过电子邮件将该zip文件作为[email protected]
的附件发送
删除压缩文件
恢复Apache,MySQL,Postgresql和机架
你可以使用下一个脚本,更新如果当然你的信息:
#!/bin/sh [ -f /etc/redhat-release ] && service httpd stop [ -f /etc/debian_version ] && service apache2 stop service mysqld stop service postgresql stop #Do the same for rack, not sure what the service is called. zip -r /tmp/all_needed.zip /etc/httpd/conf/httpd.conf /etc/httpd/conf.d/ /home/kerrick/ /var/lib/mysql/ # etc. mail -s "test" [email protected] < /tmp/all_needed.zip rm -f /tmp/all_needed.zip [ -f /etc/redhat-release ] && service httpd start [ -f /etc/debian_version ] && service apache2 start service mysqld start service postgresql start #Do the same for rack, not sure what the service is called.
如果需要,使其作为cron运行。 但确实会更好,例如scp或ftp,而不是邮件,因为zip包可能太大,将无法作为附件发送。
最简单的当然是一个作为cron作业运行的bash脚本,其中包含:
service
命令或/etc/init.d
脚本调用停止Apache,MySQL,PostgreSQL和Rack tar
命令来创build要压缩的文件的压缩包 – 将压缩包放入临时目录,例如/ tmp 另外,您可以在所有步骤之间放入“检测”命令,写入(自定义)日志文件或系统日志服务器。