Automatically Back Up the Database & Files and Email to You (Without Plugin)

As stated by the title, this post presents a way to:

  • Automatically back up the [and any WP files (directories) ]
  • Email the to you

This method makes use of the Linux jobs and therefore is useful for those whose websites are hosted on the Linux server with (as supplies cron jobs).

Two scripts realize the desired function: backup.sh and sendmail.py. The former is the bash shell script which backs up the database (files), while  the latter is the python script which emails the backup to you. Theses scripts, though very rough, were first published in the older post. Now, they have been improved and a new version comes out. This work is inspirited by Liunian.

Features of this method:
  • Automatically
  • Not only back up database, but also back up anything as you want
  • Supply a clear list of the backup in the email
  • Let the fool plugin go away
Screenshot:
Installation:
  • Download the scripts (including backup.sh and sendmail.py)
  • Create a new directory anywhere (e.g., /home/username/backup)
  • Finish the configuration in the beginning of  the file backup.sh FOLLOWING THE DIRECTIONS GIVEN THERE
  • Upload the two files backup.sh and sendmail.py to the directory created previously, and change their permissions to be 700
  • Submit the cron job in C-panel. The command usually has the form as (Here SCRIPT_DIR is the directory created previously)
    SCRIPT_DIR/backup.sh
Other notes:
  • Directions about the configuration are given below in Chinese. Only 9 lines are needed to be configured.
    ##############  Configuraion Begins  ################
     
    ##--------Configuration I: Database & WP Directories-------------
     
    ## wp-config.php所在目录
    WP_CONFIG=/home/username/public_html/wp-config.php
     
    ## 如果想明确给出数据库参数,将下面三行去掉屏蔽并参考wp-config.php填写。
    ## 但是,当前面的WP_CONFIG给出了正确的位置,这里的参数将不起作用。
    # S_DB_USER=db_user
    # S_DB_PASSWORD=db_password
    # S_DB_NAME=db_name
     
    ## 将要存放脚本 "backup.sh" 和 "sendmail.py"的目录。可自创建。
    SCRIPT_DIR=/home/username/backup_script
     
    ## 将要生成数据库备份的目录。
    DB_BACKUP_DIR=/home/username/public_html
     
    ## 其它需要备份的目录或者文件。
    ## 格式: WP_BACKUP_DIRS=(directory1 directory2 directory3).
    ## 如果不需要,直接留个空的括号。
    WP_BACKUP_DIRS=(/home/username/public_html/wp-content/themes)
     
    ##--------Configuration II: Mail Account--------------
    ## 利用站点空间提供的邮箱服务。
    ## 可以在C-panel自己创建一个邮箱帐户。
    ## 关于邮箱的相关信息可以在C-panle的 "webmail->goto webmail login->configure mail account" 中查找。
    ## 下面以ATBHOST的邮箱服务为例说明配置.
     
    ## 自定义发送者,随意。
    From=Backup@vastars.info
     
    ## 邮件接受者。
    To=receiver@gmail.com
     
    ## 站点空间的邮箱服务器。
    mail_host=server01.atbhost.net
     
    ## 邮箱帐户
    mail_user=mailuser
     
    ## 邮箱密码
    mail_pass=***
     
    ##############  Configuraion Ends  ################
  • For more information, one can refer to this older post in 中文 and this latest post in 中文

Related posts



37 comments. Leave a comment

  1. 奶牛 说道:

    还是手动备份呢,没用工具~~~

  2. Firm 说道:

    备份是每天都要做的

  3. 90后的贼 说道:

    真够费劲的说一声

  4. su 说道:

    还是看不懂啊

  5. dengmin 说道:

    为啥要用英文写呢,对我有打击的

  6. BoKeam 说道:

    我现在都手动备份

  7. 布丁 说道:

    郁闷啊!我看你排版严重错位啊!

  8. skywing 说道:

    成功了,不过全是英文看得我脑痛,不过还是谢谢博主了.

  9. 丰胸产品 说道:

    都英文,我在做梦?

  10. 指舞六弦 说道:

    呵呵,英文的哦,星尘真厉害

  11. su 说道:

    我眼花了吗 怎么都是英文啊??

  12. 小飘 说道:

    这个我觉得。。我ms看得懂。。。

  13. PARA 说道:

    我把牛津高阶找来放到电脑旁再来慢慢看 :mrgreen:
    Vastar,我的小站换了新域名http://www.iharo.com,烦请您修改一下,希望继续友情。

  14. 人好哇! 说道:

    呵呵,居然写英文的教程呢。。。牛……
    自动备份数据库和文件并发送到你的邮箱,这个功能确实不错。不过不用插件实现就有点新鲜了,找个时间我也这样试试看。

  15. 流年 说道:

    居然是英文,不错不错



Pings to this post

  1. [...] 前面对数据库和文件的自动备份和邮件发送已经写了两篇文章,第一篇只备份数据库,第二篇增加了选择备份文件夹的功能。但两个版本中的邮件发送都是通过调用一个python的smtp模块来实现的。最近发现这个python脚本不是很好用,邮件有时能收到,有时收不到。今天意外发现linux主机系统有mail函数,于是将第二个版本简化改进了下。 [...]


发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

Comment

You may use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>