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 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 中文

或许您还对这些文章感兴趣:

有一所人人都可以上的大学:


自定义搜索

Leave a Reply to Vastar (37 Responses)


Leave a Reply


:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!:

  • Research papers by P. Zhang

评论

  • 正在加载...