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

Ker*_*ick 2 backup

如果我想在 Linux VPS 上压缩(或 tar.gz 压缩)路径列表(递归),然后将 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.
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将 zip 文件作为附件通过电子邮件发送到 foobar@example.com

  4. 删除压缩文件

  5. 恢复 apache、mysql、postgresql 和 rack

Log*_*eck 5

您可以使用下一个脚本,当然更新您的信息:

#!/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" yourmail@yourdomain.com <  /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.
Run Code Online (Sandbox Code Playgroud)

如果需要,让它作为 cron 运行。但确实会更好,例如 scp 或 ftp 而不是通过电子邮件发送,因为 zip 包可能太大并且无法作为附件发送。