Results 1 to 6 of 6

Thread: How to make backup script by using TAR with using simple FTP over the another location?

  1. #1
    Join Date
    Apr 2011
    Posts
    63

    How to make backup script by using TAR with using simple FTP over the another location?

    I have installed CentOS 5.5 on the system of mine. I am looking to have some backup script by using /TAR incremental backup with the simple FTP on to another location and also email status. It should be also able to measure the time which is required to finish the process and it should remove the folder which are older than that of specific number of days. So let me know if you are having any possible solution to get the requirement of mine. Thanks a lot in advance.

  2. #2
    Join Date
    Apr 2009
    Posts
    1,107

    Re: How to make backup script by using TAR with using simple FTP over the another location?

    I am suggesting the following files which are included on the TAR in the below mentioned list.
    Code:
    /var/
    /etc/
    /home/
    Also the following list of the file which is being excluded into TAR can be listed as follow.
    Code:
    proc
    *_log*
    var/tmp
    var/lib/bluetooth
    var/lib/cs
    var/lib/dav
    var/lib/dbus
    var/lib/dhcpv6
    var/lib/dovecot
    var/lib/games
    var/lib/rpm
    var/lib/webalizer
    var/lib/yum
    var/tmp/arhiv_serverja
    var/log
    var/run
    var/www/manual
    var/yp
    var/lib/php/session
    spool
    cache
    *zip
    *gz
    etc/rc*
    home/httpd/manual
    rpm

  3. #3
    Join Date
    Nov 2009
    Posts
    1,416

    Re: How to make backup script by using TAR with using simple FTP over the another location?

    I have made the script and placed the same on the /usr/tmp/server_backup directory. One can have root access while running the script in the computer of yours.
    Code:
    PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin
    The archive.sg in /usr/local/bin is as follow.
    Code:
    #!/bin/bash
    cd /usr/tmp/server_backup
    ./backup.sh                          # the real script to make backup

  4. #4
    Join Date
    Nov 2009
    Posts
    1,292

    Re: How to make backup script by using TAR with using simple FTP over the another location?

    I am suggesting the script which you have done on the computer of yours. it is named as backup.sh and I have mentioned the same as follow.
    Code:
    #!/bin/sh
    
    # DELETE archive older than -mtime +'days'
    find . -name 'BACKUP*.tgz' -mtime +20 -delete
    find . -name 'stopwatch*' -mtime +2 -delete
    
    start1=$(date +"%T h   ( %s )")
    start=$(date +%s)
    
    # on SUNDAY make FULL backup
    if [ $(date +"%a") = "Sun" ]; then
    {
    SNAPSHOTFILE="./usr-full";				# needed by TAR (GNU-TAR to be precise) which is used to compare for incremental backups
    ARCHIVENAME=BACKUP-full-$(date +"%F-%a-%H-%M-%Sh").tgz;					# self explaining
    rm -f "./usr-full";
    }
    
    else
    {
    ARCHIVENAME=BACKUP-$(date +"%F-%a-%H-%M-%Sh").tgz;
    # a name of a backup file:  BACKUP-2009-12-15-Fri-01-15-01h.tgz
    SNAPSHOTFILE="./usr-1";
    cp "./usr-full" "./usr-1";
    }
    fi
    
    echo $ARCHIVENAME >archivename.txt		# need the name to FTP transfer so store it in file archivename.txt which doesn't change (used later in lftpscript.sh ) !
    # creating text to send in email
    echo "-----------------------" >stopwatch-$archivename.txt
    echo "Backup of $ARCHIVENAME" >>stopwatch-$archivename.txt
    echo "-----------------------" >>stopwatch-$archivename.txt
    echo " " >>stopwatch-$archivename.txt              # echo " " makes new line /CR or LF whatever it does
    # I do not need this precise time { time tar -T including.txt -X excluding.txt -pczvRf $ARCHIVENAME; } 2>> stopwatch-$ARCHIVENAME.txt >/dev/null
    { tar -T including.txt -X excluding.txt -pczvR --listed-incremental=$SNAPSHOTFILE  -f $ARCHIVENAME; } 2>> stopwatch-$ARCHIVENAME.txt >/dev/null
    
    stopped1=$(date +"%T h   ( %s )")
    stopped=$(date +%s)
    ftpstarted=$stopped
    
    thetime=$(($stopped-$start))			# doing some math in shell that's why $()
    
    echo " " >>stopwatch-$ARCHIVENAME.txt
    echo -n "File Size (Byte-s) : " >>stopwatch-$ARCHIVENAME.txt
    ls -al "$ARCHIVENAME" | cut -f 5 -d ' ' >>stopwatch-$ARCHIVENAME.txt
    # this part | cut -f 5 -d ' '   is sometimes maybe 6 instead of 5, experiment which gives you only the SIZE of the file
    echo " " >>stopwatch-$ARCHIVENAME.txt
    echo "Started: " $start1 >>stopwatch-$ARCHIVENAME.txt
    echo "Stopped: " $stopped1 >>stopwatch-$ARCHIVENAME.txt
    echo "Time needed: " $(date -d "1970-01-01 $thetime sec" +"%H:%M:%S")      /  $thetime "secs" >>stopwatch-$ARCHIVENAME.txt
    # outputs: Time needed: 00:03:14 / 194 secs
    
    
    echo "-----------------------" >>stopwatch-$ARCHIVENAME.txt
    echo " " >>stopwatch-$ARCHIVENAME.txt
    echo "FTP start:" >>stopwatch-$ARCHIVENAME.txt
    # again I dont need exact time procedure { time ./lftpscript.sh; } 2>> stopwatch-$ARCHIVENAME.txt
    { ./lftpscript.sh; } 2>> stopwatch-$ARCHIVENAME.txt
    
    ftpstop1=$(date +"%T h   ( %s )")
    ftpstopped=$(date +%s)
    
    ftptime=$(($ftpstopped-$ftpstarted))
    
    echo " " >>stopwatch-$ARCHIVENAME.txt
    echo "Start of FTP: " $stopped1 >>stopwatch-$ARCHIVENAME.txt
    echo "End of FTP: " $ftpstop1 >>stopwatch-$ARCHIVENAME.txt
    echo "Time of FTP transfer: " $(date -d "1970-01-01 $ftptime sec" +"%H:%M:%S")     /   $ftptime "secs" >>stopwatch-$ARCHIVENAME.txt
    
    mail -s "Backup of $ARCHIVENAME" "email address of recipient" <stopwatch-$ARCHIVENAME.txt
    #finally email report :-)
    So use the above mentioned and let me know if there is bug in the script which I have mentioned above.

  5. #5
    Join Date
    Nov 2009
    Posts
    1,269

    Re: How to make backup script by using TAR with using simple FTP over the another location?

    Well in this particular situation you need to untar the archive file like you do with any of the other file on the system of yours. one thing you should consider while doing the same and it seems to be really important. You should chdir to the directory where you are looking to extract the back up file on the computer. Mainly you can use /var/tmp. If you don’t do the same then the backup file of yours would be overwritten with the extracted file.

  6. #6
    Join Date
    Nov 2009
    Posts
    1,416

    Re: How to make backup script by using TAR with using simple FTP over the another location?

    You should use the below mentioned command on the terminal while extracting the backup file to the original place.
    Code:
    /var/tmp/extracted-backup/# tar xzvf /usr/tmp/server_backup/BACKUP-full-'file date you want'.tgz
    Once you have done with the above mentioned command you should copy the desired file and paste the same to the desired location. So use the same command while copying the file to the desire location.

Similar Threads

  1. How to make a simple Sorting batch file?
    By nadeth in forum Software Development
    Replies: 3
    Last Post: 18-01-2012, 06:13 AM
  2. How to make a simple Android game
    By Katyayani in forum Software Development
    Replies: 10
    Last Post: 28-12-2011, 10:48 PM
  3. Make simple gift box in Corel Draw
    By Tynan in forum Windows Software
    Replies: 3
    Last Post: 27-02-2011, 07:10 AM
  4. Replies: 4
    Last Post: 13-12-2010, 10:16 AM
  5. Will it be good to make /home/backup as dest in WHM Backup
    By Armando-H in forum Operating Systems
    Replies: 6
    Last Post: 18-06-2010, 03:34 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,673,844.52101 seconds with 17 queries