Discover Centmin Mod today
Register Now

Cron is not working

Discussion in 'System Administration' started by Sunka, Dec 16, 2015.

Tags:
  1. Sunka

    Sunka Well-Known Member

    1,003
    276
    83
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +453
    Local Time:
    2:41 AM
    Nginx 1.15.0
    MariaDB 10.2.15
    I create this four lines via crontab -e
    First and third just delete old backup if there any older than it is instructed in code
    Code:
    17 2 * * * find /home/nginx/domains/pijanitvor.com/backup/ssh_database -mtime +3 -type f -exec rm -f {} \;
    
    27 2 * * * mysqldump --opt xenforo > /home/nginx/domains/pijanitvor.com/backup/ssh_database/ssh_solo_`date +%d-%m-%Y---%H-%M`.sql
    
    45 2 * * * find /home/nginx/domains/pijanitvor.com/backup/ssh_files -mtime +0 -type f -exec rm -f {} \;
    
    57 2 * * * tar -cf - /home/nginx/domains/pijanitvor.com/public/ | gzip -c > /home/nginx/domains/pijanitvor.com/backup/ssh_files/ssh_solo_files_`date +%d-%m-%Y---%H-%M`.tar.gz
    But nothing is happened. No files or database was backup.
    If I manually run this commands, backup is created OK.
    What is wrong?


    This is my cron log entries for that four cron lines:
    Code:
    Dec 16 02:17:01 tvor-ocean CROND[13142]: (root) CMD (find /home/nginx/domains/pijanitvor.com/backup/ssh_database -mtime +3 -type f -exec rm -f {} \;)
    
    Dec 16 02:27:01 tvor-ocean CROND[13281]: (root) CMD (mysqldump --opt xenforo > /home/nginx/domains/pijanitvor.com/backup/ssh_database/ssh_solo_`date +)
    
    Dec 16 02:45:01 tvor-ocean CROND[13432]: (root) CMD (find /home/nginx/domains/pijanitvor.com/backup/ssh_files -mtime +0 -type f -exec rm -f {} \;)
    
    Dec 16 02:57:01 tvor-ocean CROND[13531]: (root) CMD (tar -cf - /home/nginx/domains/pijanitvor.com/public/ | gzip -c > /home/nginx/domains/pijanitvor.com/backup/ssh_files/ssh_solo_files_`date +)
     
  2. eva2000

    eva2000 Administrator Staff Member

    36,050
    7,910
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,192
    Local Time:
    10:41 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    try replacing the command with full path to command

    use which to find the pull path i.e. for find command full path = /bin/find

    Code:
    which find
    /bin/find
    Code:
     which gzip
    /bin/gzip
     
    Last edited: Dec 16, 2015
    • Informative Informative x 1
  3. eva2000

    eva2000 Administrator Staff Member

    36,050
    7,910
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,192
    Local Time:
    10:41 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    also putting commands in shell file might be easier and call that shell file from cron i.e.

    /root/tools/cleanup.sh place code
    Code:
    #!/bin/bash
    /bin/find /home/nginx/domains/pijanitvor.com/backup/ssh_database -mtime +3 -type f -exec rm -f {} \;
    Code:
    chmod 0700 /root/tools/cleanup.sh
    cron
    Code:
    17 2 * * * /root/tools/cleanup.sh > /dev/null 2>&1
     
    • Agree Agree x 1
  4. Sunka

    Sunka Well-Known Member

    1,003
    276
    83
    Oct 31, 2015
    Rijeka, Croatia
    Ratings:
    +453
    Local Time:
    2:41 AM
    Nginx 1.15.0
    MariaDB 10.2.15
    @eva2000 should this be OK?
    I added two full paths into fourth code (for tar and for gzip).


    Code:
    nano /root/tools/cleanup-database.sh
    #!/bin/bash
    /bin/find /home/nginx/domains/pijanitvor.com/backup/ssh_database -mtime +3 -type f -exec rm -f {} \;
    
    nano /root/tools/cleanup-files.sh
    #!/bin/bash
    /bin/find /home/nginx/domains/pijanitvor.com/backup/ssh_files -mtime +0 -type f -exec rm -f {} \;
    
    nano /root/tools/backup-database.sh
    #!/bin/bash
    /usr/bin/mysqldump --opt xenforo > /home/nginx/domains/pijanitvor.com/backup/ssh_database/ssh_solo_`date +%d-%m-%Y---%H-%M`.sql
    
    nano /root/tools/backup-files.sh
    #!/bin/bash
    /usr/bin/tar -cf - /home/nginx/domains/pijanitvor.com/public/ | /bin/gzip -c > /home/nginx/domains/pijanitvor.com/backup/ssh_files/ssh_solo_files_`date +%d-%m-%Y---%H-%M`.tar.gz
    
    
    chmod 0700 /root/tools/cleanup-database.sh
    chmod 0700 /root/tools/cleanup-files.sh
    chmod 0700 /root/tools/backup-database.sh
    chmod 0700 /root/tools/backup-files.sh
    
    crontab -e
    17 2 * * * /root/tools/cleanup-database.sh > /dev/null 2>&1
    27 2 * * * /root/tools/backup-database.sh > /dev/null 2>&1
    45 2 * * * /root/tools/cleanup-files.sh > /dev/null 2>&1
    57 2 * * * /root/tools/backup-files.sh > /dev/null 2>&1
     
  5. eva2000

    eva2000 Administrator Staff Member

    36,050
    7,910
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +12,192
    Local Time:
    10:41 AM
    Nginx 1.15.x
    MariaDB 5.5/10.x
    yeah that should work
     
    • Like Like x 1
..