Difference between revisions of "Cron"

From Wiki2
 
(7 intermediate revisions by the same user not shown)
Line 4: Line 4:
[[php www-data program that creates a crontab and calls a C program that executes root commands to copy it into crontabs and install it]]
[[php www-data program that creates a crontab and calls a C program that executes root commands to copy it into crontabs and install it]]


current crontab in /var/spool/cron/crontab/pathbost
===sitebuilt current backup setup===
<syntaxhighlight>  
scripts are in
/usr/local/lib/tim/scripts
 
 
you need composer
  apt-get update
  apt-get install curl
  apt-get install php5 git php5-curl php5-cli
  curl -sS https://getcomposer.org/installer | php
 
composer.json lists the aws php dependencies
composer install
composer update
 
aws credentails are in /root/.aws/credentials
 
<syntaxhighlight lang="bash">
#!/bin/bash
_now=$(date +"%m_%d_%Y")
_dir="/var/backups/s3/"
_file="files_$_now.tar.gz"
_bth=$_dir$_file
echo "Starting backup to $_bth..."
tar czf $_bth $(<file-dir-list.txt)
php s3_dir.php $_file
 
php s3_db.php sitebuil_wuffdb
php s3_db.php sitebuil_wikidb
php s3_db.php sitebuil_wrdp1
php s3_db.php hsc
php s3_db.php restoring
</syntaxhighlight>
 
The tar command takes a file list, it has to be correct
 
 
<pre>
<pre>
# m h  dom mon dow  command
# m h  dom mon dow  command

Latest revision as of 12:00, 12 November 2014

cron and backups

https://help.ubuntu.com/community/CronHowto

php www-data program that creates a crontab and calls a C program that executes root commands to copy it into crontabs and install it

sitebuilt current backup setup

scripts are in

/usr/local/lib/tim/scripts


you need composer

 apt-get update
 apt-get install curl
 apt-get install php5 git php5-curl php5-cli
 curl -sS https://getcomposer.org/installer | php

composer.json lists the aws php dependencies

composer install
composer update

aws credentails are in /root/.aws/credentials

<syntaxhighlight lang="bash">

  1. !/bin/bash

_now=$(date +"%m_%d_%Y") _dir="/var/backups/s3/" _file="files_$_now.tar.gz" _bth=$_dir$_file echo "Starting backup to $_bth..." tar czf $_bth $(<file-dir-list.txt) php s3_dir.php $_file

php s3_db.php sitebuil_wuffdb php s3_db.php sitebuil_wikidb php s3_db.php sitebuil_wrdp1 php s3_db.php hsc php s3_db.php restoring </syntaxhighlight>

The tar command takes a file list, it has to be correct


# m h  dom mon dow   command
0 3 * * * cd /usr/local/lib/tm/scripts; ./backup.sh
0 2 * * * find /var/backups/s3/*.gz -ctime +21 -type f -print | xargs rm -f
cron tutorial another
Re: Where is crontab stored?
Root-level crontab should be in /etc/crontab.
Root-level anacron and periodics should be in /etc/cron*
User-level crontabs should be in /var/spool/cron/crontabs - they are listed by user, pathbost isactually a chrontab
select-editor

installing and testing a crontab

installing
even after you change it by yourself you can install it by running as root
sudo crontab -u pathbost /var/spool/cron/crontabs/pathbost
testing
* * * * * /bin/echo " pathGZoobar $(date) " >> /usr/local/docs/testcron.txt

will append this every minute to testcron.txt

 pathGZoobar Thu Jan  3 14:15:01 EST 2013

You can check the logs to see if the crontab got installed/executed by running as root

sudo tail /var/log/syslog

vi with crontab 101

  • su to user then 'crontab -e'
  • 'i' to insert text
  • 'esc :wq to save change, and quit
    • then crontab is installed
  • 'esc :q!' exits without saving (or installing)
  • you can kill your crontab with crontab -r
  • you can list the installed crontab with crontab -l

backup to s3

Backups have a 30 day life on s3 and a 21 day life in /var/backups/backup backup_to_S3 code

directory backup

To backup a directory run this from the terminal:

sudo php /home/sitebuil/scripts/S3-Site-Backups/s3cli_backupDir.php /home/sitebuil/public_html/doku doku
database backup
sudo php php /home/sitebuil/scripts/S3-Site-Backups/s3cli_backupDb.php sitebuil_wiki

or goto http://pathboston.com/zstill/stillwater.html

refs

s3 backup with s3napback

string meaning

   ------ -------
   @reboot Run once, at startup
   @yearly Run once a year, "0 0 1 1 *"
   @annually (same as @yearly)
   @monthly Run once a month, "0 0 1 * *"
   @weekly Run once a week, "0 0 * * 0"
   @daily Run once a day, "0 0 * * *"
   @midnight (same as @daily)
   @hourly Run once an hour, "0 * * * *"