homepage Welcome to WebmasterWorld Guest from 54.166.159.110
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
Backup linux server
Doood

10+ Year Member



 
Msg#: 907 posted 5:10 pm on Dec 29, 2003 (gmt 0)

I need to back up my entire server and can't figure out how. I've been reading about how to use tar to do it but nobody really knows how. I found a 730 page book on how to backup but is it really that difficult that it takes 730 pages to explain?

The only thing I know is that I need to exclude /proc /dev /tmp /mnt and below is something I found as an example...

tar -zcvpf /archive/full-backup-`date '+%d-%B-%Y'`.tar.gz \
--directory / --exclude=mnt --exclude=proc --exclude=var/spool/squid .

When I do back it up, where does it go? To my local computer or somewhere on the server?

 

danny

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 907 posted 2:33 am on Dec 30, 2003 (gmt 0)

Try using rsync -- it's easier than tar (doesn't have configuration options dating back 30 years!) and also only copies those portions of files that have changed (so will be much faster if you're backing up to a different machine).

danny

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 907 posted 2:38 am on Dec 30, 2003 (gmt 0)

tar -zcvpf /archive/full-backup-`date '+%d-%B-%Y'`.tar.gz --directory / --exclude=mnt --exclude=proc --exclude=var/spool/squid .

This backs up the contents of "." -- the current directory -- into a file in /archive with a name like full-backup-30-December-2003. You only need to exclude mnt, proc, etc. if . is / (you run the command in the root directory), but if you do that you definitely want --exclude=archive as well, otherwise you'll end up backing up your previous backup files!

Doood

10+ Year Member



 
Msg#: 907 posted 8:22 am on Dec 30, 2003 (gmt 0)

Ok, I think I'm beginning to understand it now, but instead of putting it in /archive can I save it to my home computer? I'm doing the full backup because I'm about to upgrade to ensim pro 3.5, the instructions said to not backup /tmp and /dev in addition to the others mentioned also.

I haven't looked at rsync yet but will.

Ozzy

10+ Year Member



 
Msg#: 907 posted 6:26 pm on Dec 30, 2003 (gmt 0)

A quick and dirty way to backup to a remote machine would be to mount a share on your remote machine at say /mnt/remote and then backup to that...

- Ozzy

Doood

10+ Year Member



 
Msg#: 907 posted 5:24 pm on Jan 15, 2004 (gmt 0)

I'm still trying to figure out how to backup this server. It's been about a month now since I first started. Still no go.

I've seen scripts that'll do it but they pretty much require you to be an expert server admin to set it up, which I'm not. Since I only have a small number of sites, tar should work and everyone knows how to do it theoretically but can't really tell me how.

Is there an easier solution? I'm about on my last straw and I guess I'm asking for someone to spell it out for me.

wruk999

10+ Year Member



 
Msg#: 907 posted 5:48 pm on Jan 15, 2004 (gmt 0)

Doood,

Did you not get any joy out of the script I posted at:

[webmasterworld.com...]

wruk999

Doood

10+ Year Member



 
Msg#: 907 posted 6:03 pm on Jan 15, 2004 (gmt 0)

Not really sorry. I honestly don't know what I'm doing and it's all greek to me.

I'm sure it's not possible but I wish that I could just go in there and type in "backup all" and then download it, but of course nothing is that easy.

I've been looking at this below to backup but have given up on trying to figure it out.

#!/usr/bin/php
<?

#####################Customize############################
//ftp settings
$ftp=1;//ftp send (0 disable, 1 enable)
$ftphost=""; //ftp host
$ftpuser=""; //ftp user
$ftppw=""; //ftp password
$ftpfolder=""; //ftp folder (without slash infront and after)
$ftpdeleteold=1; //delete old backups (0 disable, 1 enable)
$ftpdays=7; //number of days for backup to become "old"

//save settings
$local=1; //store locally (0 disable, 1 enable)
$savepath="/backup/"; //path to store files locally
$deleteold=1; //delete old backups (0 disable, 1 enable)
$days=2; //number of days for backup to become "old"

//mysql settings
$illegaldatabases=1; //backup illegal ensim databases (0 disable, 1 enable)
$userdatabases=1; //backup all databases user has rights to (0 disable, 1 enable)

$excludelogs=1; //exclude logs from backup. (0 disable, 1 enable)
$excludeext=""; //extensions (without a dot) seperated with a space excluded from backup

$date=date("m-d-Y"); //date format of folder *NOTE* if changed change in function deleteold() also.
$tmppath="/tmp"; //temporary store directory
##########################################################

echo "Ensimbackup version 1.1\n";
switch($argv[1]){
case "-d":
if(isset($argv[2])){
backup($argv[2]);
deleteold();
}
else
echo"You need to specify a domain\n";
break;
case "-n":
if(isset($argv[2])){
$domain=trim(`/usr/local/bin/sitelookup -s $argv[2]¦awk -F\, {'print $1'}`);
backup($domain);
deleteold();
}
else
echo"You need to specify a site\n";
break;
case "-a":
backupall();
deleteold();
break;
case "-l":
backuplist($argv[2]);
deleteold();
break;
default:
echo "usage $argv[0]\n";
echo "-d [domain] domain backup\n";
echo "-n [site#] site backup\n";
echo "-a all sites\n";
echo "-l [/path/file] list file (one domain each line)\n";
break;
}

exit;

function getpw(){
$pw=trim(`cd /usr/lib/opcenter/mysql/;
python2.1 -c 'from mysqlbe import *; print read_mysqlpass();'`);
return $pw;
}

function removedirr($conn,$dirname){

$ar_files = ftp_nlist($conn, $dirname);
if(is_array($ar_files)){
for ($i=0;$i<count($ar_files);$i++){
$st_file = $ar_files[$i];
if (ftp_size($conn, $st_file) == -1){
$this->removedirr( $st_file);
} else {
ftp_delete($conn, $st_file);
}
}
}
ftp_rmdir($conn, $dirname);

}

function deleteold(){
global $savepath,$local,$deleteold,$ftpdeleteold;
global $ftp,$ftphost,$ftpuser,$ftppw,$ftpfolder;
global $days, $ftpdays;
$m=date("m");$d=date("d");$y=date("Y");

if($ftpdeleteold AND $ftp){

$conn_id = ftp_connect($ftphost);
// login with username and password
$login_result = ftp_login($conn_id, $ftpuser, $ftppw);
$dirs=ftp_nlist($conn_id,"$ftpfolder");

foreach($dirs as $dir){
$del=1;
if(ereg("^$ftpfolder/[0-9]{2}-[0-9]{2}-[0-9]{4}$",$dir)){

for ($i=0; $i<$ftpdays; $i++) {
$checkdate=date("m-d-Y", mktime (0,0,0,$m,$d-$i,$y));
if($dir=="$ftpfolder/$checkdate")
$del=0;
}

if(($del)AND($dir!="")){
echo"Removing on ftp $dir.. ";
removedirr($conn_id,$dir);
echo"done\n";
}
}

}

}

if($deleteold AND $local){
unset($dirs);
$dirs=array();
if ($handle = opendir($savepath)) {
while (false!== ($file = readdir($handle))) {
if (ereg("^[0-9]{2}-[0-9]{2}-[0-9]{4}$",$file)){
$dirs[]=$file;
}
}
closedir($handle);
}
foreach($dirs as $dir){
$del=1;
for ($i=0; $i<$days; $i++) {
$checkdate=date("m-d-Y", mktime (0,0,0,$m,$d-$i,$y));
if($dir==$checkdate)
$del=0;
}

if(($del)AND($dir!="")){
echo"Removing $savepath/$dir.. ";
`rm -rf $savepath/$dir`;
echo"done\n";
}

}
}

}

function xmldump($domain,$site,$path){
global $tmppath;
echo "Dumping account details.. ";
`python2.1 -c "
import sys;
from vh3 import virthost;
xml_dict = {'doctype':'backup','author':'appliance','type':'site','site':'$site'}
xml_list=virthost.create_site_xml(xml_dict)
print (xml_list)

" > $tmppath/$domain.xml`;
`cd $tmppath; gzip $domain.xml`;
echo "done\n";

}

function checkmysql($site){
global $addmysql;
$addmysql="";
$pw=getpw();
$check = file ("/home/virtual/$site/info/current/mysql");
$check[1]=trim($check[1]);
if($check[1]=="enabled = 1"){
return 1;
}
else{
return 0;
}
}

function mysqlbackup($path,$db,$site,$domain){
global $addmysql,$illegaldatabases,$userdatabases;
$pw=getpw();
$check = file ("/home/virtual/$site/info/current/mysql");
$dbadmin=str_replace("dbaseadmin = ","",trim($check[3]));
$connect = mysql_connect("localhost", "root", $pw);
mysql_select_db("mysql",$connect);
$result=mysql_query("select password from user where user='$dbadmin'");
$line=mysql_fetch_object($result);
`echo '$dbadmin\n$line->password' > $path/mysql`;

if($userdatabases){
unset($databases);
$grants=trim(`mysql -e 'SHOW GRANTS FOR \`$dbadmin\`@localhost' -u root --password=$pw`);
preg_match_all("/ON `?(.*?)`?\.\* TO/",$grants, $databases);
foreach($databases[1] as $database){
if($database!=$db AND $database!="*"){
$database=str_replace('\_','_',$database);
echo "Dumping database $database.. ";
`mysqldump -u root --password=$pw --add-drop-table --add-locks --quote-names --extended-insert $database > $path/$database.sql`;
echo "done\n";
}
}
}

if($illegaldatabases){
unset($databases);
$list=trim(`mysql -e 'show databases' -u root --password=$pw`);
preg_match_all("/^$domain$/m", $list,$databases);
foreach($databases[0] as $database){
echo "Dumping database $database.. ";
`mysqldump -u root --password=$pw --add-drop-table --add-locks --quote-names --extended-insert $database > $path/$database.sql`;
echo "done\n";
}

}
else{
echo "Dumping database $db.. ";
`mysqldump -u root --password=$pw --add-drop-table --add-locks --quote-names --extended-insert $db > $path/$db.sql`;
echo "done\n";
}

$addmysql="*.sql mysql";
}

function delmysqlbackup($path,$db){
if($path!="")
`rm -f $path/*.sql`;
if(!@unlink("$path/mysql"))
echo "Couldn't delete mysql";
}

function tarsite($path,$domain,$site){
global $addmysql,$tmppath,$excludelogs,$excludeext;
echo "Tarring $path.. ";
$exts=explode(" ",$excludeext);
$extline="";
foreach($exts as $ext){
$extline.="--exclude=*.$ext ";
}

$excludelog="";
if($excludelogs){
$excludelog="--exclude=var/log/*";
}
`cd $path; tar -zcf $tmppath/$domain.tgz $excludelog $extline etc/httpd etc/mail etc/shadow etc/aliases etc/aliases.db home var $addmysql`;
`cd $tmppath; tar -cf $domain.tar $domain.tgz $domain.xml.gz`;
unlink("$tmppath/$domain.tgz");
unlink("$tmppath/$domain.xml.gz");
echo "done\n";
}

function upload($domain){
global $ftphost,$ftpuser,$ftppw,$ftpfolder;
global $date,$tmppath;
echo "Uploading file.. ";
`ncftpput -m $ftphost -u$ftpuser -p$ftppw $ftpfolder/$date $tmppath/$domain.tar > /dev/null 2>&1`;
echo "done\n";
}

function copyfile($domain){
global $date,$tmppath,$savepath;
if(!file_exists("$savepath/$date")) {
mkdir("$savepath/$date");
}
echo "copying file $domain.tar.. ";
`cp $tmppath/$domain.tar $savepath/$date/$domain.tar`;
echo "done\n";
}

function backup($domain){
global $tmppath,$ftp,$local;
#get variabels
$path=trim(`/usr/local/bin/sitelookup -d $domain ¦ awk -F\, {'print $4'}`);
if($path==""){
exit;
}
$site=trim(`/usr/local/bin/sitelookup -d $domain ¦ awk -F\, {'print $3'}`);
$db=str_replace(".","_",$domain);

#dump mysql database
$mysqlcheck=checkmysql($site);

if($mysqlcheck)
mysqlbackup($path,$db,$site,$domain);
else
echo "$domain has no database\n";

#xml dump
xmldump($domain,$site,$path);

#backup dirs
tarsite($path,$domain,$site);

#remove database back-ups
if($mysqlcheck)
delmysqlbackup($path,$db);

#upload the file
if($ftp){
upload($domain);
}

if($local){
copyfile($domain);
}
unlink("$tmppath/$domain.tar");
echo "\n";
}

function backupall(){
$sites=trim(`/usr/local/bin/sitelookup -a ¦ awk -F\, {'print $1'}`);
$sites=explode("\n", $sites);
foreach($sites as $site){
backup($site);
}
}

function backuplist($listfile){
$sites = file ("$listfile");
foreach($sites as $site){
$site=trim($site);
backup($site);
}
}

?>

ruserious

10+ Year Member



 
Msg#: 907 posted 10:29 am on Jan 16, 2004 (gmt 0)

Are you on a _managed_ dedicated Server, or are you doing all configuration/installation/updateing of the server-software yourself?
Because if it's managed machine, and your hosting company will set up the basic-server software, the only stuff you'd really need to safe were your own data, probably mainly being:
- everything in the docroot of the webserver (e.b. htdocs/
- everything in the database
- possibly more files/application that you use, but have put outside webserver-docroot for security reasons.

This would really make it a lot easier to regularly backup that machine.

Doood

10+ Year Member



 
Msg#: 907 posted 7:44 pm on Jan 16, 2004 (gmt 0)

No it's not managed hosting, I have to do everything myself. I'll figure it all out one of these days, until then, I will continue to be constantly confused.

donb01

10+ Year Member



 
Msg#: 907 posted 12:10 am on Feb 20, 2004 (gmt 0)

I know that people tend to hate graphical administration tools for security reasons, but I'm going to suggest this anyway...

If you don't have webmin loaded on your system you may wish to grab it and install it. Webmin has a menu item for backing up your system to a variety of media and using a variety of options. It can shield you from the command line a bit, if necessary.

I have had good results using this to backup my system.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved