Required STUFF:
1-: php5-cli (Not exactly php5 but php cli)
2-: Crontab
3-: A Brain
First step:
make a file named: auto_backup.sh
Inside this file put this:
Note: This file needs executable permission, for more information read this tutorial: http://otland.net/f138/permissions-chmods-71960/
Second step:
Execute the following command:
Your computer should have open an empty file with a command text editor named nano
There you have to write:
Then click F3 to save and F2 to exit and thats all! From now your computer will make a backup everyday.
Also i would like to thank Kornholijo for always answering my n00b questions (Noob for him, hardcore for me xD).
--EDIT
If you get any error (Not about permissions) try changing:
[/FONT][/COLOR]
for
[/COLOR]
1-: php5-cli (Not exactly php5 but php cli)
2-: Crontab
3-: A Brain
First step:
make a file named: auto_backup.sh
Inside this file put this:
PHP:
#!/usr/bin/php5 -q
<?php
$startTime = array_sum(explode(" ",microtime()));
//Credits: www.dagondesign.com and Migxxx
/*
@Mysql Configuration.
*/
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_password = 'your_mysql_password';
/*
@Backup Destination.
*/
$backup_dest = '/home/migxxx/db_backups';
ignore_user_abort(1);
set_time_limit(0);
$n = "\x0A"; //newline
$spacer = str_repeat('-',82);
echo($spacer.$n.'Making BACKUP:'.$n);
if(!is_dir($backup_dest))
mkdir($backup_dest);
if(!is_dir('/tmp/db_bp_'.$unique = uniqid()))
mkdir('/tmp/db_bp_'.$unique);
$db_conn = @mysql_connect($mysql_host,$mysql_user,$mysql_password) or die("Coudn't stablish connection with MYSQL.".$n);
$db_result = mysql_list_dbs($db_conn);
$db_auth = ' --host="'.$mysql_host.'" --user="'.$mysql_user.'" --password="'.$mysql_password.'"';
while($db_row = mysql_fetch_object($db_result))
{
$db_time = array_sum(explode(" ",microtime()));
$db = $db_row->Database;
echo($n.$db);
exec('/usr/bin/mysqldump '.$db_auth.' --opt '.$db.' 2>&1 >/tmp/db_bp_'.$unique.'/'.$db.'.sql');
exec('nice -n 19 bzip2 /tmp/db_bp_'.$unique.'/$db.sql 2>&1');
if(is_file('/tmp/db_bp_'.$unique.'/'.$db.'.sql'))
echo(' --DONE ('.round(( array_sum(explode(' ',microtime())) - $db_time),4).' sec)');
}
mysql_free_result($db_result);
mysql_close($db_conn);
exec('cd /tmp/db_bp_'.$unique.'/ ; nice -n 19 tar cf '.$backup_dest.'/db_backup'.date('Y-m-d-h:i:s_M_D').'.tar * 2>&1');
echo($n.$n.'Backup Done in: '.round(( array_sum(explode(' ',microtime())) - $startTime),4).' sec.'.$n.$spacer.$n.'Removing TMP files/folders:'.$n);
if($dir = @opendir('/tmp/db_bp_'.$unique.'/'))
while(($file = readdir($dir)) !== false)
if(!is_dir($file))
{
echo($n.$file);
if(unlink('/tmp/db_bp_'.$unique.'/'.$file))
echo(' --DONE');
}
closedir($dir);
echo($n.'/tmp/db_bp_'.$unique.'/');
if(rmdir('/tmp/db_bp_'.$unique.'/'))
echo(' --DONE');
echo($n.$n.'Files and folder removed, Script END in a total of: '.round(( array_sum(explode(' ',microtime())) - $startTime),4).' sec.'.$n.$n.'Date: '.date("l d F Y, h:i:s A").$n.$spacer.$n);
?>
Note: This file needs executable permission, for more information read this tutorial: http://otland.net/f138/permissions-chmods-71960/
Second step:
Execute the following command:
Code:
crontab -e
There you have to write:
Code:
1 1 * * * /home/migxxx/auto_backup.sh
Also i would like to thank Kornholijo for always answering my n00b questions (Noob for him, hardcore for me xD).
--EDIT
If you get any error (Not about permissions) try changing:
Code:
[COLOR=#000000][FONT=Courier New]#!/usr/bin/php5 -q
for
Code:
[COLOR=#000000]#!/usr/bin/php -q
Last edited: