Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I need to create a cron job to back up some directories on centos to network disk. Any ideas suggestions? Many thanks in advance...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    16

    how to access network disk in Centos


    Hi,

    I need to create a cron job to back up some directories on centos to network disk. Any ideas suggestions?

    Many thanks in advance

  2. #2
    Just Joined!
    Join Date
    Jun 2012
    Location
    Spain
    Posts
    6
    Hi,
    Yes this is a very simple task, create a script like this and run at midnight.

    Before run the script ensures that the remote network disk is mounted in the /usr/local/NFSDISK, because the script will check the /usr/local/NFSDISK/bck directory before start the bck

    Add in the /etc/fstab the correct mount order

    Code:
    #!/bin/bash
    
    # LIST OF DIRECTORIES TO BCK
    
    LIST="/home /etc /var/spool/cron /usr/local"
    
    # SOME VARIABLES
    
    BACKUP_BASE_LOGS="/var/spool/logs"
    BACKUP_REMOTE="/usr/local/NFSDISK/bck"
    BACKUP_DIR="/"
    BACKUP_DATE_DIR=`date +%A`
    BACKUP_LOG="Backup.log"
    BACKUP_DATE=`date +%c`
    LOG_RSYNC="$BACKUP_BASE_LOGS/rsync.log"
    
    # Check if the remote DISK is mounted
    
    [ -f $BACKUP_BASE_LOGS/$BACKUP_LOG ] || touch $BACKUP_BASE_LOGS/$BACKUP_LOG
    
    if [ ! -d $BACKUP_REMOTE ]; then
            {
            echo "The remote disk is not mounted!!!!" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            echo " Trying mounting the disk in $BACKUP_REMOTE" PATH >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            mount -a >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            }
            if [ ! -d $BACKUP_REMOTE ]; then
            {
            echo "Error when trying to mount the remote disk" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            echo "Exit" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            exit 1
            }
    fi
    
    echo "[$BACKUP_DATE] Synchronized the remote directory" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
    
    [ -d $BACKUP_REMOTE/$BACKUP_DATE_DIR ] || mkdir $BACKUP_REMOTE/$BACKUP_DATE_DIR
    touch $BACKUP_REMOTE/$BACKUP_DATE_DIR/FLAG
    
    #Now
    for d in $LIST; do
    
            [ -d $BACKUP_REMOTE/$BACKUP_DATE_DIR$d ] || mkdir -p $BACKUP_REMOTE/$BACKUP_DATE_DIR$d
            rsync --links --delete --force --ignore-errors -a $d/* $BACKUP_REMOTE/$BACKUP_DATE_DIR$d > $LOG_RSYNC 2>&1
            BACKUP_DATE_DIR=`date +%A`
            echo "[$BACKUP_DATE] Directory $d copy in $BACKUP_REMOTE/$BACKUP_DATE_DIR" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
    
    done
    -----

    Alberto Larripa
    Sysadmin & DBA
    Website: Sysadmin and DBA tips

  3. #3
    Just Joined!
    Join Date
    Dec 2010
    Posts
    16
    Quote Originally Posted by larry54 View Post
    Hi,
    Yes this is a very simple task, create a script like this and run at midnight.

    Before run the script ensures that the remote network disk is mounted in the /usr/local/NFSDISK, because the script will check the /usr/local/NFSDISK/bck directory before start the bck

    Add in the /etc/fstab the correct mount order

    Code:
    #!/bin/bash
    
    # LIST OF DIRECTORIES TO BCK
    
    LIST="/home /etc /var/spool/cron /usr/local"
    
    # SOME VARIABLES
    
    BACKUP_BASE_LOGS="/var/spool/logs"
    BACKUP_REMOTE="/usr/local/NFSDISK/bck"
    BACKUP_DIR="/"
    BACKUP_DATE_DIR=`date +%A`
    BACKUP_LOG="Backup.log"
    BACKUP_DATE=`date +%c`
    LOG_RSYNC="$BACKUP_BASE_LOGS/rsync.log"
    
    # Check if the remote DISK is mounted
    
    [ -f $BACKUP_BASE_LOGS/$BACKUP_LOG ] || touch $BACKUP_BASE_LOGS/$BACKUP_LOG
    
    if [ ! -d $BACKUP_REMOTE ]; then
            {
            echo "The remote disk is not mounted!!!!" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            echo " Trying mounting the disk in $BACKUP_REMOTE" PATH >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            mount -a >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            }
            if [ ! -d $BACKUP_REMOTE ]; then
            {
            echo "Error when trying to mount the remote disk" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            echo "Exit" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
            exit 1
            }
    fi
    
    echo "[$BACKUP_DATE] Synchronized the remote directory" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
    
    [ -d $BACKUP_REMOTE/$BACKUP_DATE_DIR ] || mkdir $BACKUP_REMOTE/$BACKUP_DATE_DIR
    touch $BACKUP_REMOTE/$BACKUP_DATE_DIR/FLAG
    
    #Now
    for d in $LIST; do
    
            [ -d $BACKUP_REMOTE/$BACKUP_DATE_DIR$d ] || mkdir -p $BACKUP_REMOTE/$BACKUP_DATE_DIR$d
            rsync --links --delete --force --ignore-errors -a $d/* $BACKUP_REMOTE/$BACKUP_DATE_DIR$d > $LOG_RSYNC 2>&1
            BACKUP_DATE_DIR=`date +%A`
            echo "[$BACKUP_DATE] Directory $d copy in $BACKUP_REMOTE/$BACKUP_DATE_DIR" >> $BACKUP_BASE_LOGS/$BACKUP_LOG
    
    done
    -----

    Alberto Larripa
    Sysadmin & DBA
    Website: Sysadmin and DBA tips

    Many thanks Larry much appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •