在我的VPS上压缩重要文件并将它们发送给我自己的最简单的方法是什么?

如果我想在Linux VPS上压缩(或者tar.gz)一系列path(recursion地),然后将ZIP / TAR发送给我自己,然后删除ZIP / TAR,那么最简单的方法是什么? 一个cron作业,一个程序等的shell脚本?

例如,这是我可能做的事情:

  1. 停止apache,mysql,postgresql和rack

  2. 拉链拉上:

    /etc/httpd/conf/httpd.conf /etc/httpd/conf.d/* /home/kerrick/* /var/lib/mysql/* # etc. 
  3. 通过电子邮件将该zip文件作为[email protected]的附件发送

  4. 删除压缩文件

  5. 恢复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
  • 使用任何可以处理附件的邮件程序发送tarball – 或 –
  • 对tarball进行base64编码,并将结果传送给邮件程序
  • 删除/ tmp中的tarball(或者你正在使用的任何目录)
  • 再次启动服务

另外,您可以在所有步骤之间放入“检测”命令,写入(自定义)日志文件或系统日志服务器。