Skip to content

Instantly share code, notes, and snippets.

@AjayKumar01
Created July 7, 2016 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AjayKumar01/cbc6fb8f7bba931de0983bc8b9cafd3f to your computer and use it in GitHub Desktop.
Save AjayKumar01/cbc6fb8f7bba931de0983bc8b9cafd3f to your computer and use it in GitHub Desktop.
Script to take backup of file system daily basis
#!/bin/bash
#Script to take autodump of directories
#Written by Ajay Kumar
#Dated: 07 July 2016
BACKUPDIR="/home/restore/CRM_Backup/"
TODAY=`date +"%A"`
#enter directories to be backedup here
FILES=( '/var/www/html/sugarhome' )
#create directory if doesn't exist
if [ ! -d "$BACKUPDIR" ]; then
mkdir -p "$BACKUPDIR"
fi
#iterate over files array
for dir in "${FILES[@]}"; do
#check if directory
if [ -d "$dir" ]; then
#filename concatenated with weekday
filename=$BACKUPDIR$(basename $dir)_${TODAY}.zip
zip -rq $filename $dir
fi
done
----
Add the below entry in crontab
0 10 * * * sh /root/cronfiles/daily_file_dump
This will take backup of everyday at 10 AM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment