backUpScript/backupApache.sh
2022-06-25 17:32:00 -04:00

35 lines
564 B
Bash
Executable File

#! /usr/bin/bash
if [[ $UID != 0 ]]; then
echo "Please run this using sudo"
exit
fi
prefix=backup_apache2
fileName=$prefix-$(date +'%m-%d-%Y').tar.gz
dir=$(pwd)
echo "====== check number of old backup"
nBackup=$(ls -1 $prefix-* | wc -l)
echo "number of backup : ${nBackup}"
if [[ $nBackup -gt 3 ]]; then
oldFile=$(ls -t $prefix-* | tail -1)
echo "removing the old backup $oldFile"
rm -f $oldFile
fi
echo "====== backup apache data"
cd /etc
tar -czf $fileName apache2/
ls -l $fileName
mv $fileName $dir/.
echo "backup saved to ${fileName}"