The Feng Office Wiki has instructions for backing up the Feng Office installation folder and the MySQL database. This can either be done with scripts and a cron job or with a plugin that allows for configuration via the Administration web console and a cron job.
In this post I will look at the scripts and cron job – I intend to look at the plugin later on.
Backing up Feng Office for me this means backing up /var/www/feng_community as well as the fengdb database.
In my previous post I mounted a share on my Windows Home Server in Ubuntu Server using the following mount point /mnt/whs-backup.
Note: Your Feng Office installation folder, database variables and backup destination may differ so adjust them as required.
To run a nightly backup I need two brief scripts, a secure file that contains the MySQL username and password, and two cron entries to run the backups.
Update: In the comments potion pointed out that the cp command does not file owner/group or permissions. So I have added his suggested scripts for the tar command.
Here are the explanations of the tar switches used:
-c, --create create a new archive -f, --file=ARCHIVE use archive file or device ARCHIVE -x, --extract, --get extract files from an archive
Note: the following two scripts are saved in my /home/username folder.
The first script will back up /var/www/feng_community:
#!/bin/bash sudo cp -R /var/www/feng_community /mnt/whs-backup
#!/bin/bash today=$(date '+%d_%m_%y') sudo tar -cf /mnt/whs-backup/"$today"_feng_community.tar /var/www/feng_community
I saved this file as backup-feng-community.sh
The second script will backup the fengdb database and query a secured file /etc/fengdb.cnf for MySQL credentials:
#!/bin/bash mysqldump --defaults-extra-file=/etc/fengdb.cnf fengdb > /mnt/whs-backup/fengdb.sql
I saved this file as backup-fengdb.sh.
Now we need to make these two scripts executable:
chmod +x backup*.sh
Create a file called /etc/fengdb.cnf:
sudo nano /etc/fengdb.cnf
Add the following lines using your MySQL fengdb username and password:
[client] host = localhost user = fenguser password = yourfengdbpassword
In nano press Ctrl + O and then Enter to save and then Ctrl + X to exit.
Secure /etc/fengdb.cnf as follows:
sudo chmod 600 /etc/fengdb.cnf
At this point we could execute the two scripts manually and backup Feng Office to our Windows share.
To automate the backup we use cron. This is what my cron settings look like (my two scripts are set to run everyday around 1am).
# m h dom mon dow command 15 1 * * * /home/username/backup-feng-community.sh * 1 * * * /home/username/backup-fengdb.sh
Change username to your Ubuntu Server username.
To edit your cron settings use the following command:
sudo crontab -e
You can use my settings or you can easily generate your own cron settings using the online cron generator.
If you have configured Feng Office to communicate with email accounts such as Gmail be prepared for the backup of /var/www/feng_community to take a little while (depending of how many email and attachments have been downloaded).
As with any backup we also need to know how to restore the backups. For this we need two scripts. The first I named restore-feng-community.sh:
#!/bin/bash sudo cp -R /mnt/whs-backup/feng_community /var/www
sudo tar -xf /mnt/whs-backup/*_feng_community.tar var/www/feng_community
In the tar restore above the * refers to the date of the backup.
The second script (to restore the MySQL database) I named restore-fengdb.sh:
#!/bin/bash mysql --defaults-extra-file=/etc/fengdb.cnf fengdb < /mnt/whs-backup/fengdb.sql
Again, make both of these scripts executable:
chmod +x restore*.sh
For the record I did test the restore process before posting! Please take precautions when you test restoring your backups (and make sure that you change the appropriate variables in the scripts to match your environment).