Thread: Re: Cron jobs and backup

Re: Cron jobs and backup

From
Aarni Ruuhimäki
Date:
Hi Carlos,

Did you get your backup going ?

Here's what I actually did for automatically backing up my Postgres data from
remote machine.

1. On remote machine I have crons for vacuuming and dumping all data daily ( =
nightly) and  'incrementally' with datestamps:

/usr/local/pgsql/bin/vacuumdb -a

/usr/local/pgsql/bin/pg_dumpall -c > /usr/local/pgdumps/all/all_`date
"+%d-%m-%y"`

Similar dumps for MySQL as well.

2. I created id_rsa and id_rsa.pub keys for my backup-user on local machine.

cd /home/backup-user/.ssh/

ssh-keygen -t rsa -N ""

3. I moved and copied the id_rsa.pub key line to remote
machine's /home/backup-user/.ssh/ and named it to authorized_keys2

4. I wrote a shell script which I cron jobbed for my local backup-user:

-------------
#!/bin/sh
cd /var/remote_backup # here we fetch stuff

# ssh-connect and give commands from batch file
ssh xxx.xxx.xxx.xxx  < /etc/backup_from_remote/ssh-B.batch

# sftp-connect and give commands from batch file
sftp -b /etc/backup_from_remote/sftp-B.batch xxx.xxx.xxx.xxx

# xxx.xxx.xxx.xxx = remote ip-address
#eof
-------------

ssh-B.batch looks like this:

-------------
#cd /somewhere/ # here we tar
#tar czvf name.tar.gz /path/somewhere #what we tar
#no tarring or anything, just exit the batch
exit
-------------

sftp-B.batch looks like this:

-------------
cd /usr/local/pgdumps/all/ #where we fetch from
get *
rm *
exit
-------------

This fetches and removes whatever you have in the remote directory where we
get the dumps from remote crons.

Logging and email reporting would be nice too ...

Best regards,

Aarni

--------------
This is a bugfree broadcast to you
from **Kmail**
on **Fedora Core 2** linux system
--------------


>>>>>>>>>>
Hi Carlos,

You can find sample scripts here:

http://tennis.ecs.umass.edu/~czou/linux/backupSSH.html

Modify them to your needs, they are quite straight forward. I would not allow
root remote login, though.

Not sure about the logs with all commands and results or sending email,
something I been wondering to do too, but as I sit in front of my backup
machine every work day I see if the files have come down or not and have not
yet bothered. Another thing on the 'to do' list ...

Best regards,

Aarni

On Thursday 04 August 2005 19:30, Carlos Bergueira wrote:
> Hi Aarni ,
>  Could you pls help me ?
> I need to create a cron job to backup some especifics folders sftp'ing the
> gzip file from a server to another one.
> I know how tar and gzip folders i want.
>  Could you pls send me the script for:
> - SFTP'ing the gzip file;
> - Create a log with all commands and results;
> - Sending e-mail to administrator system if the backup was done succesfully
> or not.
> Thanks.
>  --
> Rgds,
> Carlos Bergueira