Howto: Backup CentOS / Fedora Linux / Red Hat Enterprise Linux server system

by on July 26, 2007 · 3 comments· LAST UPDATED July 26, 2007

in

Q. How do I backup files and database for the Red Hat Enterprise Linux / CentOS Linux? Currently I’ve MySQL server running on CentOS 5 and Web server and file server using RHEL 5. How do I backup all these servers?

A. Regular backup is an essential for Linux system. You can take backup on
=> Tape
=> NAS Server
=> DVD
=> Network server etc

Implementing a backup policy that includes rotating backup media and keeping copies of backup media offsite is the most reliable way of minimizing damage. See following resources on our site for more information including commands and shell scripts:

  1. Perform backups for the Linux operating system
  2. How to backup MySQL databases, web server files to a FTP server automatically
  3. Howto Backup PostgreSQL Databases
  4. All backup shell scripts
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 3 comments… read them below or add one }

1 Don Armstrong July 14, 2009 at 12:18 am

If you only have one server, simply use tar and you are done. If you take your data seriously, you should consider a commercial network backup software that is friendly to Linux and open source like Arkeia. Arkeia Network Backup does hot backup of PostgreSQL, MySQL and about 100 linux distros (it even included in the Ubuntu and Mandriva repository).

Reply

2 Ganapathi August 29, 2012 at 10:49 am

I have an some files in cent os.I need to schedule auto backup that files to the another file storage server directory. I need that script.will you please anyone post that script.

Source : Cent Os
Destination : Samba File storage server( another directory).

Reply

3 Shankar September 6, 2012 at 6:12 am

a backup script on centos to take periodic backups , change the names and customize it for your system.

#!/usr/bin/env bash
#---------------------
exit_on_error () {
    if [ $? -ne 0 ]; then
        logger -s "bezkon:backup script failed";
        exit 1;
    fi
}
# we are done with the mount
# now try to create the date folder
# in the "/media/backup_disk/database_snapshots" folder
create_snapshot_folder ()
{
    logger -s "bezkon:backup trying to create the snapshot folder";
    mkdir -p $1;
}
# try to copy the redis and mysql files to the destination folder.
copy_files_to_snapshot_folder ()
{
    logger -s "bezkon:backup trying to copy the database files to the folder";
    cp -rf "/var/lib/mysql/repository"/* $1;
    cp -rf "/dump.rdb" $1;
    cp -rf "/var/log/bezkon/"/* $1;
}
# unmount the file system as we are done with it
unmount_backup_disk ()
{
    logger -s "bezkon:backup unmounting the backup drive";
    umount $1;
    #remove the directory as we are done
#    if [ -d "$1" ]; then
#    logger -s "bezkon:backup Trying to remove the destination dir";
#            rm -rf $1;
#    fi
}
mount_backup_disk ()
{
    logger -s "bezkon:backup Trying to mount the backup disk";
    #create the directory if its not present
    if [ ! -d "$2" ]; then
   logger -s "bezkon:backup Trying to create the destination dir";
   mkdir -p $2;
    fi
    mount $1 $2;
}
#cron job for taking redis and mysql backups
#we just take a daily backup instead of rsync or snapshot scheme
logger -s "bezkon:backup task started";
#start with a clean slate
mount_src="/dev/sda1";
mount_dst="/media/backup_disk";
#unmount_backup_disk $mount_dst;
#directory is there means its already mounted no need to remount
#if [ ! -d "$mount_dst" ]; then
#    mount_backup_disk $mount_src $mount_dst;
#    exit_on_error;
#fi
# get the current time of the day
# and create the snapshot folder
now=$(date +"%m-%d-%Y")
snapshot_folder="/media/backup_disk/database_snapshots/snapshot_$now"
create_snapshot_folder $snapshot_folder;
exit_on_error;
copy_files_to_snapshot_folder $snapshot_folder;
exit_on_error;
#sleep 300;
unmount_backup_disk $mount_dst;
exit_on_error;
# return the success status 0 to our caller "cron".
logger -s "bezkon:backup task complete";
exit 0;

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: