Home »Networks

Linux web server backup script

27 July 2008 491 views No Comment

Everyone knows that nowadays normally very important to take backups. This is not such a pleasant work and there often comes a long time. If you have a linux web server, you can automate this task very easy. In this tutorial I'll leave a small bash script to see your web files with a backup of your MySQL database into a tar.gz (like a zip) file sets.

Bash backup script

This script is not the best script that there is only work and is very compact. You can do it more as a preview for your own backup script to build.

Bash script example

The script itself is as follows:

  0 
  1 
  2 
  3 
  #!  / bin / bash 
  mysql gebruikersnaam ]  -p [ mysql wachtwoord ] [ databasenaam ] >  mysql_backup.sql mysql dump-u [mysql username]-p [password mysql] [database name]> mysql_backup.sql 
  ` date  + % Y % m % d ` .tar.gz / var / www / html mysql_backup.sql tar-czf `date +% Y% m% d`. tar.gz / var / www / html mysql_backup.sql 
   mysql_backup.sql rm-f mysql_backup.sql 

The first line ensures that the bash shell is used for the script to run. The second line is a sql backup of the database you specify. Note that between p and your password is no space. Then, a tar of the web files and mysql backup. Tar This will be named today's date will be. The folder shows you can change the folder that you want to back up. Finally, the mysql_backup file removed.

Put the script in a file called backup.sh. Give the rights with the following command.

  0 
  chmod u + x backup.sh 

Now you can run the script with:

  0 
  . / Backup.sh 

The resulting tar file, you can in a safe place so you always have a backup if something should go wrong.

This article shall: Places / votes on NUjij Places / voices eKudos Post / vote at MSN Reporter Places / votes on Bligg.nl Post / vote at MSN Reporter Places / votes on Bligg.be Places / votes on Netjes.be Post / vote at Digg Stumble it! Add this article to Del.icio.us Add to Furl Add to your favorites on Technorati Add to your Google Bookmarks Add to your Facebook profile You subscribe to the RSS feed of this site Put this message on Twitter
Send article to a friend
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...


Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

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

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.