www backup script

Here is a simple script that creates a RAR file of /var/www/

1. Create a script folder.
# sudo mkdir /script

2. Create a backup folder and a destnation folder for the www rar file.
# sudo mkdir /backup /backup/www

3. Create a script file.
# sudo nano /script/wwwbackup.sh

Add the following:
#!/bin/bash
/usr/bin/rar a -r /backup/www/www.rar /var/www/

This will will create a rar file of the www directory. The file patch will be /backup/www/www.rar

When done exit Nano and save he script file.

4. Verify that the script file is correct.
# sudo cat /script/wwwbackup.sh

5.  Give the script execution rights.
# sudo chmod +x /script/wwwbackup.sh

6. Instal Cron (Same as schedule tasks in Windows)
# sudo aptitude install cron

7. Edit crontab.
# crontab -e

Add the following t crontab:
15 23 * * * /script/wwwbackup.sh

This means that wwwbackup.sh will start every day 23.15.

8. Verify crontab.
# crontab -l

9. Verify the next day that the backup file exists in /backup/www/.

Run the wwwbackup script manually:
# /script/./wwwbackup.sh

MySQL backup script

1. Create a script folder.
# sudo mkdir /script

2. Create a backup folder and a destnation folder for the MySQL files.
# sudo mkdir /backup /backup/mysql

3. Create a script file.
# sudo nano /script/mysqlbackup.sh

At the start of the file add:
#!/bin/bash

On the next row write your script.

Here are a few script examples. In the examples the MySQL user is  root and the password is Qwerty12.

Example 1. Will backup alla databases into one single file.
#!/bin/bash
/usr/bin/mysqldump –u root pQwerty12 –all-databases > /backup/mysql/all-databases.sql

Example 2. Will backup the database named mysite.
#!/bin/bash
/usr/bin/mysqldump –u root pQwerty12 –databases mysite > /backup/mysql/mysite.sql

When done exit Nano and save he script file.

4. Verify that the script file is correct.
# sudo cat /script/mysqlbackup.sh

5. Give the script execution rights.
# sudo chmod +x /script/mysqlbackup.sh

6. Instal Cron (Same as schedule tasks in Windows)
# sudo aptitude install cron

7. Edit crontab.
# crontab -e

Add the following t crontab:
01 23 * * * /script/mysqlbackup.sh

This means that mysqlbackup.sh will start every day 23.01.

8. Verify crontab.
# crontab -l

9. Verify the next day that the backup file exists in /backup/mysql/.

Run the mysqlbackup script manually:
# /script/./mysqlbackup.sh