The below is the script to backup files in linux :
- copy the below script and name example.sh
-----------------------------------------------------------------------------------------------------------------------------------------
#!/bin/bash
#START
TIME=`date +"%b-%d-%y_%H-%M-%S"`
FILENAME="backup-$TIME.tar.gz"
SRCDIR="/path/to/source/folder" #please change to your source folder
DESDIR="/path/to/destination/folder" # please change to your destination folder
tar -cpzf $DESDIR/$FILENAME $SRCDIR
find /path/to/destination/folder/ -iname '*.tar.gz' -ctime +45 -exec rm -f {} \; #please change to your destination folder
#END
-----------------------------------------------------------------------------------------------------------------------------------------
- And change the mode of file example.sh
-----------------------------------------------------------------------------------------------------------------------------------------
#chmod +x example.sh
-----------------------------------------------------------------------------------------------------------------------------------------
- And move the examle.sh file
-----------------------------------------------------------------------------------------------------------------------------------------
#mv example.sh /bin/
-----------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------
#sudo crontab -e
45 22 * * * example.sh #Edit as your requirement
-----------------------------------------------------------------------------------------------------------------------------------------