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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 4 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
4 comments… add one
  • Don Armstrong Jul 14, 2009 @ 0:18

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

  • Ganapathi Aug 29, 2012 @ 10:49

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

  • Shankar Sep 6, 2012 @ 6:12

    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;
  • sekhar Aug 29, 2014 @ 1:59

    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.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum