Page 1 of 1

Data Backup Process Suggestions

PostPosted: Apr 24th, '14, 22:27
by mbramble
Running Mageia 4 with a 1 TB internal drive and a 120GB external usb drive. I would like to copy my /home directory to the usb drive and then have cron run a command each night to copy over any files that have been changed.

Any suggestions on the best way to do this??

Thanks,
Mike

Re: Data Backup Process Suggestions

PostPosted: Apr 24th, '14, 23:00
by doktor5000
Maybe some details on your intentions about this to help understand the context?

Do you want to move your /home folder to the external drive, or only copy/duplicate the files to the external drive (as in a backup).

Re: Data Backup Process Suggestions

PostPosted: Apr 24th, '14, 23:07
by madeye
I would suggest using rsync to do that. But it depends on what you are comfortable with. Me I like the console ;-)
Below I have listed the script I use to do my backup. But of course there exists alot of other options like e.g. storebackup (http://savannah.nongnu.org/projects/storebackup)

Code: Select all
#!/bin/bash
###############################################################################
#
# Script to make a backup of files using rsync.
# It rotates directories automatically.
#
# To ensure the backupdrive is mounted, the script checks for the existance of a file named
# 'mount_OK' (without the quotes)
#
# Created 2014 by Rene Rasmussen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA  02110-1301, USA.
#
###############################################################################

# Backup drive mountpoint
backup_drive="/mnt/backer"

# Parent backup directory
backup_parent_dir="${backup_drive}/homeback"

# Number of backups
# (number of directories in rotation)
# count starts from 0, so below value defines directories+1
backup_dir_count=12

#initialize errors variable
errors=0

# Check if drive is mounted
# (check for mount_OK file)
okFile=${backup_drive}/mount_OK
if [ -f $okFile ]
then
   # If the destination folder does not exist, it will be created
   if [ ! -d $backup_parent_dir ]
   then
      mkdir -p $backup_parent_dir
      chmod 750 $backup_parent_dir
   fi
   # Rotate backup directories
   for (( c=$backup_dir_count; c>=2; c-- ))
   do
      if [ $c -eq $backup_dir_count ]
      then
         dirPath=${backup_parent_dir}/backup$c
         #echo "0 = $dirPath" #debug
         if [ -d $dirPath ]
         then
            rm -rf $dirPath
         fi
      fi
         dirPath1=${backup_parent_dir}/backup$((c-1))
         dirPath2=${backup_parent_dir}/backup$c
         #echo "1 = $dirPath1" #debug
         #echo "2 = $dirPath2" #debug
         if [ -d $dirPath1 ]
         then
            mv $dirPath1 $dirPath2
         fi
   done
   # copy contents from backup0 to backup1 with hardlinks
   dirPath1=${backup_parent_dir}/backup0
   dirPath2=${backup_parent_dir}/backup1
   if [ -d $dirPath1 ]
   then
      cp -al $dirPath1 $dirPath2
   fi
   # remove old datestamp file from rsync destination
   if test -n "$(find $dirPath1 -maxdepth 1 -name 'MyBackup*' -print -quit)"
   then
      rm $dirPath1/MyBackup*
   fi
   # sync files to backupfolder
   rsync -aq --delete /home $dirPath1
   # create datestamp (empty) file
   touch $dirPath1/"MyBackup from $(date '+%A, %d %B %Y, %T')"
else
   errors=1
fi

# Error handling
if [ $errors != 0 ]
then
   # Select error message based on errors value   
   # errors = 1 => Backup drive not mounted
   fdesc="ERROR with database backup"
   case $errors in
      1)
         fbody="Backup location not accessible! Please investigate cause!"
         ;;
      *)
         fbody="Something went wrong. Please investigate!"
         ;;
   esac
   # Error message for screen
   echo $fdesc
   echo $fbody

   ## error email for admin
   receiver="admin@example.com"

   echo $fbody | mail -s "$fdesc" $receiver

   exit
fi

## rsync options
# The option -n can be used to make a dry-run

# The option -P shows the progress

## Description of option switches
# Option -C => CVS exclude
# Option -v => Verbose
# Option -r => Rercursive
# Option -t => Times
# Option -p => Permissions


# An alternative to the above options is option -a
# Option -a => -rlptgoD

# Option -r => Rercursive
# Option -l => links
# Option -p => Permissions
# Option -t => Times
# Option -g => Group
# Option -o => Owner
# Option -D => devices & specials


Just add a cron job for it, and of it goes at the time you specify :)

Re: Data Backup Process Suggestions

PostPosted: Apr 24th, '14, 23:54
by doktor5000
doktor5000 wrote:Do you want to move your /home folder to the external drive, or only copy/duplicate the files to the external drive (as in a backup).

Nevermind, forgot to look at the thread title :lol:

Re: Data Backup Process Suggestions

PostPosted: Apr 25th, '14, 08:15
by filip
I use rsnapshot and it works great.