V
V
VA2016-09-28 10:03:56
linux
VA, 2016-09-28 10:03:56

Cron job not running?

I can’t figure out how to make cron work to perform file archiving and mysql database backup
tried various options
1. I made a script of this type

spoiler
#!/bin/bash

echo $(date +%y%m%d)
cd /home/bitrix/ext_www/
echo "Add site web-site.ru to archive ...Start"
tar -czpf web-site_newsite.tar.gz ./web-site.ru
echo "Add site to archive ...Done!"

echo "Move archive to backup directory"
mv web-site_newsite.tar.gz /home/backup/web-site-$(date +%y%m%d).tar.gz 
echo "Move archive to backup directory ...Done!"

cd /home/backup/
echo "Make backup database newshop"
mysqldump --single-transaction -u root dbweb-site > dbweb-site-$(date +%y%m%d).sql
echo "Make backup database newshop ...Done!"

cd /backup

find . -mtime +20 -exec rm {} \;

made it executable:
chmod +x /home/script-web.sh
in /var/spool/cron/root file added
then
18 9 * * * /home/script-web.sh
tried
18 9 * * * root /home/script-web.sh
like this
18 9 * * * bash /bin/bash /home/script-web.sh
23 9 * * * tar -czf /home/backup/backup_newsite.tar-$(date +%y%m%d).gz /home/bitrix/ext_www/web-site.ru > /dev/null 2>&1

3. Created a file in /etc/cron.daily
spoiler
#!/bin/bash

echo $(date +%y%m%d)
cd /home/bitrix/ext_www/
echo "Add site web-site.ru to archive ...Start"
tar -czpf web-site_newsite.tar.gz ./web-site.ru
echo "Add site to archive ...Done!"

echo "Move archive to backup directory"
mv web-site_newsite.tar.gz /home/backup/web-site-$(date +%y%m%d).tar.gz 
echo "Move archive to backup directory ...Done!"

cd /home/backup/
echo "Make backup database newshop"
mysqldump --single-transaction -u root dbweb-site > dbweb-site-$(date +%y%m%d).sql
echo "Make backup database newshop ...Done!"

cd /backup

find . -mtime +20 -exec rm {} \;

wrote in the file /etc/crontab
18 9 * * * root run-parts /etc/cron.daily
none of this helped

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
VA, 2016-09-28
@Ozymandis

The database was backed up as it should, but with a file backup of the site, its archive is obtained with a weight of 1kb

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/home/root/bin

tar -czpf /home/backup/web-site-$(date +%y%m%d).tar.gz  /home/bitrix/ext_www/web-site.ru/

cd /home/backup/

mysqldump --single-transaction -u root dbweb-site > /home/backup/dbweb-site-$(date +%y%m%d).sql

A
Alexey Shumkin, 2016-09-29
@ashumkin

in scripts launched from cron'a, it is better to specify the full path to the utilities used,
or set the required PATH in the crontab file (or in the script itself),
because PATH cronis very "truncated" when launched from 'a (you can check it by running in cron'e echo $PATH > /home/.../path.log)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question