LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-10-2002, 01:46 AM   #1
DigiCrime
Member
 
Registered: Dec 2002
Location: St. Louis
Distribution: All Flavors
Posts: 193

Rep: Reputation: 30
Thumbs up Backing up Linux to a remote server!


For 3 hours im searching for this answer and came across this website. Which Im glad to cause im a newb to linux and prefer it over any O/S so I might frequent this board a lot.

Dont flame me as I dont really know where to post this since Im new here


Here is what i'm looking for...

I want to backup the entire server, onto another server. Files, Configurations, Email, SQL Databases, EVERYTHING basically take an image of the current drive, and upload it to another server.

My client asked me if I could make a script that would do just this but he wants it to shut down current processes, create an archive of the backup, taring and gziping everything, so when you unzip, it would unzip back to its original state, and upload it to a remote server, and set this up as a cron job. I think he's asked the impossible as I cant really think of a way to make a shell script that would disable any current processes, and start the backup. The archive used for backup, id prefer tar.gz

Any help would be SOO greatly appreciated as Im exhausted looking for the answer.
 
Old 12-10-2002, 03:12 AM   #2
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,155

Rep: Reputation: 56
mkdir /backup

mount 192.168.0.1:/share /backup

cd /

tar czvf /backup/slacker-12-10-02.tar.gz . --exclude backup --exclude proc --exclude tmp
 
Old 12-10-2002, 03:23 AM   #3
DigiCrime
Member
 
Registered: Dec 2002
Location: St. Louis
Distribution: All Flavors
Posts: 193

Original Poster
Rep: Reputation: 30
Quote:
mount 192.168.0.1:/share /backup
this does what exactly

Quote:
tar czvf /backup/slacker-12-10-02.tar.gz . --exclude backup --exclude proc --exclude tmp
and this backsup the entire server/configs/database?


Im looking at this script right now that might do the trick but im very leary of it.. think it will work??

PHP Code:
#!/bin/sh

######################################################################
# Automated backup script of mysql and user sites for ensim 3.0.     #
# This script will dump the default database structure and data using#
# mysqldump to the sites root directory.                 # 
# This script will only backup the DEFAULT mysqldb created when you  #
# add the user in the format of domain_tld.                          #
#
# There is no warranty, i hold no responsibility for any damage you  #
# cause by not knowing what you are doing.                 #
######################################################################  

######################################################################
# Script configuration you must enter valid FTP information          # 
# This script will connect to server VIA ftp and make the directory  #                         
# where the backup files will be uploaded. The directory is in the   #
# format of YYYY-MM-DD/ the backscript. It will then execute         #
# createpickle.py and pass ite the ftp arguments!                    #
#                                     #
# You must also specify the mysqld root pass in order to dump the    #
# users database and back it up to there home directory before the   #
# backup.                                     #
######################################################################
PATH=/bin:/sbin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin

###################### CONFIG PARAMETERS #############################

ftpuser="someuser"
ftppass="somepass"
ftphost="someserver.com"
date=`/bin/date +%Y-%m-%d`
mysqlpid="/var/run/mysqld/mysqld.pid"
mysqlrootpass="somepass";


#####################################################################
### DONT CHANGE ANYTHING BELOW UNLESS YOU KNOW WHAT YOU ARE DOING ###
#####################################################################

######################################################################
# Check to see if the ftp info is valid otheriwse exit             #
######################################################################

FTP=`ncftpput $ftphost -u$ftpuser -p$ftppass  ./ /tmp/uploadtest >/tmp/.ftptest 2>&1`
check=`/bin/cat /tmp/.ftptest| grep 'not accepted'`
if [ -
"$check" ]; then
    
echo "FTP USER / PASS not accepted exiting....."  
    
exit 1
fi

############################################################################
# Check mysql databases and tables fix corrupted databases using myisamchk #
# and isamchk We must first stop mysqld it should only take a few minutes  #
############################################################################

##########################
# Attempt to stop mysqld #
##########################

mysqladmin -p$mysqlrootpass shutdown

if [ -f $mysqlpid ]; then
    
echo "mysqld couldnt be stopped exiting.. ";
    exit 
1;
else 
    echo 
"Mysql has been stopped will checking MYI and ISM tables for every user DB"
    
echo ""
    
echo ""

    
myisamchk --silent --force --fast --update-state -O key_buffer=64M 
              
-O sort_buffer=64M -O read_buffer=1M -O write_buffer=1M 
              
/var/lib/mysql/*/*.MYI
    isamchk --silent --force -O key_buffer=64M -O sort_buffer=64M \
            -O read_buffer=1M -O write_buffer=1M /var/lib/mysql/*/
*.ISM
fi 


###########################################
# Checks finished lets start mysqld again #
# if it doesnt start we need to exit      #
# because we wont be able to dump the DB. #                  
###########################################

echo ""
echo "Starting MYSQLD"
/etc/rc.d/init.d/mysqld start
echo ""

if [ -f $mysqlpid ]; then
        
echo "";
else 
    echo 
"Mysqld didnt start please start it... exiting...."
    
exit 1;

fi


###########################################################################
# Backup user databases by using mysqldump and gzipping it too          #
# /home/virtual/domain.xxx/mysql-domain_xxx.gz                  #
###########################################################################

mysql_db=`sitelookup -a | awk -F\, {'print $1'} | tr "." "_"`
for 
II in $mysql_db; do
db_dir="/var/lib/mysql/$II"
if [ -d $db_dir ]; then
   domain
=`echo $II | tr '_' '.'`
   echo 
"Backing up mysql db $II"
    
mysqldump -p$mysqlrootpass $II gzip >/home/virtual/$domain/mysql-$II.gz 
else
   echo 
"$II Doesnt Exist skipping to next..."
fi

done


echo "Making directory $date to upload files to"
touch /tmp/uploadtest
ncftpput 
-m $ftphost -u$ftpuser -p$ftppass $date /tmp/uploadtest > /dev/null 2>&1

site
=`sitelookup -a | awk -F\, {'print $3'}`

for 
II in $site; do
echo 
"Creating Pickle and backing up $II"
./createpickle.py $II $ftpuser $ftppass $ftphost | /usr/lib/opcenter/vhbackup/vhbackup
done 
 
Old 12-10-2002, 04:36 AM   #4
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,155

Rep: Reputation: 56
the mount command would mount an nfs share on the computer that you are putting the backup on

if it's a MS windows machine you could change that to mount a windows share

the tar command will backup the entire system to the computers hard drive that you mounted with the exception of the backup folder itself, the proc folder, and the tmp folder

you do not backup a proc folder because it is dynamic, however you do need the empty folder there if you restore a system

I guess you could use --exclude proc/*

so the folder would be in the backup

you could also do the same with the tmp folder or just backup the whole tmp folder if you want.

Last edited by DavidPhillips; 12-10-2002 at 04:37 AM.
 
Old 12-10-2002, 04:40 AM   #5
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,155

Rep: Reputation: 56
I think that it would not be a bad idea to backup the database with that script or one like it before running the tar backup

the script may not work exactly as is it depends on your database name and location

Last edited by DavidPhillips; 12-10-2002 at 04:46 AM.
 
Old 12-10-2002, 04:41 AM   #6
DavidPhillips
Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,155

Rep: Reputation: 56
you can unmount the share after the backup finishes using this

umount /backup
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
backing up remote folder with rsync and ssh ohcarol Linux - Software 6 01-03-2005 01:43 AM
Backing up remote Linux Server to Local Win2KPro CD-RW over SSH McK66 Linux - General 3 06-08-2004 10:05 PM
Backing up solaris files on linux server phahn Linux - Newbie 5 10-05-2003 08:09 AM
how can I remote shutdown other WinNT server from Linux Server? adelel Linux - Networking 2 01-06-2002 01:21 AM
how to remote linux server yaya Programming 1 08-25-2001 04:17 AM


All times are GMT -5. The time now is 06:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration