Back up files in linux

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/
-----------------------------------------------------------------------------------------------------------------------------------------
  • Now edit crontab
-----------------------------------------------------------------------------------------------------------------------------------------
 #sudo crontab -e

 45 22 * * * example.sh    #Edit as your requirement
-----------------------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Start and Stop ssh-agent

Below is the bash script used to start and stop ss-agent #!/bin/bash ## in .bash_profile SSHAGENT=`which ssh-agent` SSHAGENTARGS="...