Crontab in linux for backup

2

I made a sh in linux to extract in a compressed folder the copy of my MySql database. (Here's the sh)

#!/bin/sh
mysqldump -unombreusuario -pclave --opt nombrebd > nombrecarpeta/nombrebackup_$(date +%d%m%Y).sql
cd nombrecarpeta
tar -zcvf nombrebackup_$(date +%d%m%Y).tgz *.sql
rm nombrebackup_$(date +%d%m%Y).sql

This sh perfectly creates the folder for me.
Now, I have difficulty when doing the cron that makes the copy automatically at a certain time of the day since I can not find the file, my distribution of linux is centos and until now I do not know what else to do.

    
asked by Santiago Muñoz 22.08.2016 в 19:51
source

1 answer

3

Well, you only have to create your own crontab file. To do this you must use the command:

  

$ crontab -e

With this you will be able to edit the crontab file of your user and it will be stored in / var / spool / cron / so that the system updates it automatically.

As a reminder, the format of the crontab file is:

minuto hora dia mes dia-semana comando
*        *    *  *    *    

Run your script every day at 10:30:

30 10 * * * usuario /home/usuario/scripts/tuscript.sh

When you want to delete the contents of your crontab file:

  

$ crontab -r

When you want to see the contents of your crontab file:

  

$ crontab -l

I hope I have understood you well ;-)

    
answered by 23.08.2016 / 20:59
source