Data Backup Process Suggestions

This forum is dedicated to basic help and support :

Ask here your questions about basic installation and usage of Mageia. For example you may post here all your questions about getting Mageia isos and installing it, configuring your printer, using your word processor etc.

Try to ask your questions in the right sub-forum with as much details as you can gather. the more precise the question will be, the more likely you are to get a useful answer

Data Backup Process Suggestions

Postby mbramble » Apr 24th, '14, 22:27

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
mbramble
 
Posts: 13
Joined: Nov 25th, '13, 02:33

Re: Data Backup Process Suggestions

Postby doktor5000 » Apr 24th, '14, 23:00

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).
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18071
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Data Backup Process Suggestions

Postby madeye » Apr 24th, '14, 23:07

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 :)
- Madeye

When I supply commands in an answer, please make sure you understand them before you run them! Use google or man to check!
User avatar
madeye
 
Posts: 110
Joined: Jul 23rd, '11, 12:36
Location: Aabenraa, Denmark

Re: Data Backup Process Suggestions

Postby doktor5000 » Apr 24th, '14, 23:54

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:
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18071
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Data Backup Process Suggestions

Postby filip » Apr 25th, '14, 08:15

I use rsnapshot and it works great.
filip
 
Posts: 478
Joined: May 4th, '11, 22:10
Location: Kranj, Slovenia


Return to Basic support

Who is online

Users browsing this forum: No registered users and 1 guest