Wednesday, August 17, 2016

How to Create Backup of all User's Home Directory and Save as individually

This is how to blog, Create Backup of User's home directory and keep a separate compress file for each user.

For a System Administrator is required to keep the backup of Data to avoid unnecessary recovery or Disaster.

Requirement -

1- Linux box - In my scenario, I am using Centos 6.4 final release.
2- TAR utility.

Step 1 -

Create Backup destination directory or Mount NAS. In my scenario, I am using my local / root partition for demonstration.
[root@cent ~]#  mkdir /backupdir

Step 2 - 

Create #!/bin/bash Script to create backup and email report.
Create Script file using Vi editor

[root@cent backupdir]# vi homebackup.sh

#!/bin/bash
# Add your backup dir location, and tar commmand path
DATE=`date +%d_%m_%Y_%H_%M`
# Define Backup Directory
BACKUP_DIR="/backupdir"
# To create a new directory into backup directory location
mkdir -p $BACKUP_DIR/$DATE

# List all Folder available inside /home directory
USERS=`ls /home | xargs -r`
for user in  $USERS; do
tar -czf $BACKUP_DIR/$DATE/$user.tar.gz /home/$user
# Create log file for all folder comes in backup
ls -l $BACKUP_DIR/$DATE | cat > $BACKUP_DIR/$DATE/$DATE.log
done


Save and Exit from Script

Step 3 -
Make Script Executable.
[root@cent backupdir]# chmod a+x homebackup.sh

Step 4 -

Run Script to check test - If everything goes well output should like this -

[root@cent backupdir]# ./homebackup.sh


We have successfully configured Backup of folder as compress and report.


That's All
!!!Cheers!!!

No comments:

Post a Comment