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

in Categories , last updated July 26, 2007

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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 4 comments/add one below):

4 comment

  1. 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).

  2. 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).

  3. 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;
    # 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;
        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
    #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;
    # get the current time of the day
    # and create the snapshot folder
    now=$(date +"%m-%d-%Y")
    create_snapshot_folder $snapshot_folder;
    copy_files_to_snapshot_folder $snapshot_folder;
    #sleep 300;
    unmount_backup_disk $mount_dst;
    # return the success status 0 to our caller "cron".
    logger -s "bezkon:backup task complete";
    exit 0;
  4. Hi,
    I am new to shell programing. I am working under REDHAT Linux and want a script which will enable me to backup one of my folder to external usb drive on hourly basis.

    Have a question? Post it on our forum!