Thursday, September 14th, 2006
Maintaining a regular backup of your blog / database
Today in this blog about Palm will focus more on the 'blog' in the 'Palm'. I think what comes next can be quite interesting to people, even those who do not have a blog but another type of service or website that uses databases, whether portals, forums, etc..
A few days ago as you know I upgraded the version of WordPress (software CMS that works with this blog) to version 2.0.4, which is proving stable and unproblematic. However, it has encountered a problem. First things first.
WordPress has by default a plugin to make regular backups of the database, from which you can retrieve all the posts, comments, and other information after a disaster, or clone the full blog on a new server. His name is wp-db-backup and does a great job with the ability to save the backup on our server, or send it by email, and most importantly, combined with the plugin wp-cron, we could schedule a backup of up daily, and we arrived by email.
The plugin is excellent, and in fact I've used without problems for months. But unfortunately, their development was stopped a year ago, and version 2.0.4 of WordPress is no longer functioning the ability to schedule backups. The same author informs us in this review that has stopped working on it, and has not tested this latest version. So unless another developer takes over and correct the plugin will not work in this and subsequent versions of WordPress.
We certainly do not want to have to run by hand every day the plugin, because I knew that sooner or later (or rather before) was to forget. So looking through the network, and testing various alternatives, I have finished writing a simple script in Bash that performs a daily backup of the database and saves it on the server, keeping the N latest versions and deleting the above. Also you could add the option of sending the file via email, but on my server I have no chance. It would only add one line of code:
/ bin / mail-s "subject" "address" <file
For this script to work, the server hosting the blog you have to use Linux, using MySQL as database software, and give them the ability to create regular jobs in Cron. The script is as follows:
mysqldump --add-drop-table --user "nombre_usuario" --password="contraseña" "base_de_datos" | gzip -9 > /home/"usuario_cpanel"/"directorio_backup"/"base_de_datos".`date --iso-8601`.gz
ls -t /home/"usuario_cpanel"/"directorio_backup"/"base_de_datos".* | tail +"número_copias_más_1" | xargs rm -f
Seen this way it looks horrible (they are really only two lines in this narrow column format are cut), but after a while give you a link to download it directly and configure it. All the quotation marks are data that you you will have to replace the corresponding values (without the quotes). Take his explanation one by one:
- "Username": the name of the user accessing the database. It's you had to write to the wp-config.php file during installation.
- "Password" the password to access the database. It's you had to write to the wp-config.php file during installation.
- "Dbname", the name of the database. Also what you had to write to the wp-config.php file during installation.
- "Usuario_cpanel" is your username on the server hosting. Surely is that you use to access the control panel.
- "Directorio_backup" means the directory in which backups saved. You must create you for example by entering your FTP account. I recommend it in the root directory, which is nothing else to access. You'll have to give write permissions for that script can use it (this is done through the attributes of the directory you have just created, any decent FTP program will let you change them). For example try these 777 (read / write permission for all). If that directory is outside the directory where you save the contents of your WordPress installation (typically public_html), no one can access it via web.
- "Número_copias_más_1" just that. If you want to save the last three copies, put a 4.
To better understand the script, as you would see specific data:
mysqldump --add-drop-table --user paco --password=paquito pacodb | gzip -9 > /home/paco_server/mysql_backups/pacodb.`date --iso-8601`.gz
ls -t /home/paco_server/mysql_backups/pacodb.* | tail +3 | xargs rm -f
You can download the code directly into a text file. I call db_backup.sh eg, you change the above variables by your example, and you go up by FTP to the root of your server. In the file attributes, you have to give execute permission for user and group, for example Put 754. You are ready to use.

Example of a panel cPanel, which set the Cron
Now we have to create the cron job to execute it periodically. That is done from the control panel of your account on the server. For example, the server hosting this blog that you read, the software uses cPanel as control panel, and will surely be the case with many others, because of its popularity. In my case the option is called Cron jobs. We went and chose a new one. As command to execute, enter the path to our script, for example:
/home/pepe/backup.sh
And as frequency, say every six hours, all days, months and years. Unix Cron format line would look like to add:
0 */6 * * * /home/pepe/backup.sh
Save the changes, and it is scheduled to run our script every six hours. That is, four times a day will become a copy of our database in this directory. Shall accrue daily archives for the day you say, and when they are older than that, it erased. With this system, if some day we put our foot to change something on the blog, we can return to a previous state easily, by following these instructions.
I hope that the process has been fairly clear, even if you never tinkering with Cron jobs or databases, will be better than someone more used to working with servers you a hand. In return, you will have a backup of your blog, believe me, time is worth its weight in gold.
By: Mark Gonzalez Troyes in Palm Tips
| Comments RSS | Trackback |
Print this post
Related articles
| Share: |




































Cachis, you've anticipated my purpose. "I kidnappers.
For me it is important to send a compressed database specific to a GMail account, will not be compromising a server (cracking, hard drive crash, ...).
cPanel is not implemented by default. Two weeks ago, someone I know, I sent my suggestion to deploy in the next version.
- A greeting in my first speech --
PS is the most useful entry I've read lately. However, neither comment nor wag. Country of ...
It is the world's most elegant solution but it works, so I decided to share it. That option in cPanel you from making would be great. It costs nothing to add, may limit the frequency with which they send email, to avoid overloading the server.
A greeting and you find more interesting things on the blog
Maty think you should not talk like someone might take offense if they have not posted is that perhaps could not, or have not read but that we habemos many years Mark and of course to The Tungsten PDA he knows that if posteamos You will still be grateful for what for some is a necessity for others that, I apologize if I offend you because it is not my intention greetings.
@ Jose Cedano
It is widespread in the Hispanic blogosphere. And the more interesting is the note, less the number of comments. And except for some sites, most of the comments just enrich the annotation.
What nobody can deny, reading trackbacks, is to try my acquaintances know about this method.
A very interesting entry. I remember one of the glitches of the plugin you mentioned at the beginning for backups was this.
Best bash with a plugin in PHP which could contain errors and / or vulnerabilities (such as common in PHP). With bash and cron need not depend on Wordpress
I point your recipe, Mark!
Torrie Wilson in Playboy
http://myblog.es/torrie-wilson
I see this entry very interesting because as AlucardX says is much safer than a script in php. But I have to say that maybe not everyone can afford a housing payment which will bring about cron tasks. For those who are still tied to the payment servers have to go to plugins die because our freedoms are limited.
But make it clear that I consider this method the best option when the server will allow.
Puedorealizar "as a backup home directory to a file? What are the tar commands needed to create compressed backups, such as cheaquearlas and desconprimirlas?