Monday, August 2, 2021

 How to backup the OS mount point in Linux

 

#!/bin/sh
####################################
#
# Backup to /backup mount script.
#
####################################

# List of files to backup.
backup_files="/home /var /etc /root /boot /opt /bin /lib64 /lib /sbin /tftpboot /usr"

# Backup location.
dest="/u00/backup/appl/OSBKP/"

find $dest -mtime +8 -type f -exec rm -rf {} \;

# Archive Name.
day=$(date +%Y%m%d.%H%M)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"
Log_file="/u00/backup/appl/OSBKP/$hostname-$day.txt"

# Print start status message.
echo "Backing up $backup_files to $dest/$archive_file" >> ${Log_file}
date  >> ${Log_file}
echo  >> ${Log_file}

# Backup the files using tar.
tar czf $dest/$archive_file $backup_files

# Print end status message.
echo
echo "Backup finished" >> ${Log_file}
date  >> ${Log_file}

# Long listing of files in $dest to check file sizes.
ls -lh $dest  >> ${Log_file}


 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home