LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Backing up Linux to a remote server! (https://www.linuxquestions.org/questions/linux-general-1/backing-up-linux-to-a-remote-server-37814/)

DigiCrime 12-10-2002 12:46 AM

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.

DavidPhillips 12-10-2002 02:12 AM

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

DigiCrime 12-10-2002 02:23 AM

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 


DavidPhillips 12-10-2002 03:36 AM

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.

DavidPhillips 12-10-2002 03:40 AM

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

DavidPhillips 12-10-2002 03:41 AM

you can unmount the share after the backup finishes using this

umount /backup


All times are GMT -5. The time now is 05:20 PM.