Debug School

rakesh kumar
rakesh kumar

Posted on • Edited on

How to automating git commands and database backup using corn job

step1: create script file

 touch script.sh
Enter fullscreen mode Exit fullscreen mode

step2: write all git commands

git add --all
git commit -m"Weekly Backup"
git pull origin master
git push origin master
Enter fullscreen mode Exit fullscreen mode

step3: open text editor to automate git commands


export EDITOR=vi
crontab -e
Enter fullscreen mode Exit fullscreen mode

step4: open text editor to automate git commands

0 3 * * 0 /bin/bash /opt/lampp/htdocs/cloudopsnow/weekly-backup.sh
Enter fullscreen mode Exit fullscreen mode

Automating Database backup

/opt/lampp/bin/mysqldump --opt -Q -h localhost --no-tablespaces -u root --password='Hs?gb?S345' sresc  | gzip -9 > /opt/lampp/htdocs/sresc/.bkp/sresc-$(date +%d_%m_%Y).gz
Enter fullscreen mode Exit fullscreen mode

set corn job

0 3 * * 0 /bin/bash /opt/lampp/htdocs/cloudopsnow/weekly-backup.sh
Enter fullscreen mode Exit fullscreen mode

set permission

chmod +x script.sh
Enter fullscreen mode Exit fullscreen mode

OTHER use of corn job
command every day at 3:00 AM.

0 3 * * * php /bin/bash /opt/lampp/htdocs/motoshare.in artisan optimize:clear
============OR another way================
using./pull.sh
Enter fullscreen mode Exit fullscreen mode

This deletes logs older than 7 days every Sunday at midnight.

0 0 * * 0 find /bin/bash /opt/lampp/htdocs/motoshare.in/storage/logs -type f -name "*.log" -mtime +7 -delete
Enter fullscreen mode Exit fullscreen mode

Top comments (0)