Updating Packages and Backing up in crontab?

Hi,

I'm currently trying to setup nightly automatic backups and updates for my system.

I have all my commands run on a script and I tie that into a crontab task.

The script is as follows

Code:
#for updating packages
service plexmediaserver stop
service syncthing stop
pkg update -fq
pkg upgrade -fqy
pkg upgrade -fqy py27-dateutil
pkg upgrade -fqy py27-magic
pkg upgrade -fqy gnupg
pkg upgrade -fqy py27-s3cmd
pkg upgrade -fqy multimedia/plexmediaserver
pkg upgrade -fqy syncthing
service syncthing start
service plexmediaserver start

#for backing up my files to amazon S3
s3cmd="sh /s3/upload2.sh"
timestamp="$(date +"%m-%d-%Y_%H:%M")"
#upload2.sh includes the commands to start upload
touch /var/log/s3/s3upload.$timestamp.log
screen -dmS s3sync ${s3cmd} >> /var/log/s3/s3upload.$timestamp.log
#which initiates a screen session to initiate backup... though, I don't think it properly outputs to the file I specified.

And so the output I get in my inbox is

Code:
/updapps/update.sh: service: not found
/updapps/update.sh: service: not found
/updapps/update.sh: pkg: not found
/updapps/update.sh: pkg: not found
/updapps/update.sh: pkg: not found
/updapps/update.sh: pkg: not found
/updapps/update.sh: pkg: not found
/updapps/update.sh: pkg: not found
/updapps/update.sh: pkg: not found
/updapps/update.sh: pkg: not found
/updapps/update.sh: service: not found
/updapps/update.sh: service: not found
/s3cd/s3upload.sh: screen: not found

So in this case, can I assume that using a script would not work for this task?

I would greatly appreciate your help on this matter.

Thanks in advance,
Michael L.
 
cron uses a very limited environment, in particular your PATH may not include all the directories it usually does. So, in your script use the full path for the commands e.g. /usr/sbin/pkg and /usr/sbin/service.

H
 
I would recommend not updating packages automatically, that's going to bite you someday. Sometimes packages move or get renamed and updating will require additional steps. You also need to update all packages, not only some of them.
 
But manually upgrading many clients might be tedious from a certain number on.
I typically update 20-30 servers in an afternoon by hand. In general I plan this in advance (I need to kick off a bunch of poudriere jobs beforehand). Then test, then do the all the updates. For servers I would recommend tracking the quarterly branches, these normally only have a few updates. Too few to warrant doing this daily.

If you have more servers there are probably better ways to update (Puppet, Ansible, etc).
 
Ah okay I see, thanks for your responses,

In my case, I am only running in a home environment. Thus I don't absolutely need a script to update. I wouldn't mind updating manually.

Though, I would still like to run automated backups to S3 using my script and have the output sent to a .log

How can I go about this?

The current script I run from cronjob is as such.

Code:
s3cmd="sh /s3/upload2.sh"
timestamp="$(date +"%m-%d-%Y_%H:%M")"
#upload2.sh includes the commands to start upload
touch /var/log/s3/s3upload.$timestamp.log
screen -dmS s3sync ${s3cmd} >> /var/log/s3/s3upload.$timestamp.log

and upload2.sh is this:
Code:
#timestamp
timestamp(){
    date +"%Y_%D_%H:%M"
}

#start upload
#append start time
timestamp
s3cmd sync --delete-removed --recursive -v --limit-rate=500k -s /mnt/zfile/ s3://tanks3/backups/
#append end time
timestamp

The error I get is screen not found. I assume that I also need to declare path directory here. But I'm having a hard time finding it. How do I go about this?
 
Back
Top