Bash script for database backup
Hi,
I need a bash script wich connects from my debian server to another debain server via ssh. Changes there to root and executes a pg_dump command. Afterwards the script should copie the file via scp back on my debian server where it schould be renamed with the actual date. I know the single commands but I don't know how to get it in a bash script. (especially the ssh and root password) Can anyone help me with this problem?? Many thanks!!!! |
Hi
First you need to setup key based ssh authentication. From the first server, run the command "ssh-keygen -t rsa" as root. Hit enter when it asks you for a passphrase. It will generate two files in "/root/.ssh". Copy "/root/.ssh/id_rsa.pub" over to the other server, and rename it to "/root/.ssh/authorized_keys". Then verify that you can ssh to the server without typing the password. Then, you can run commands on the other server by passing them as options to ssh. The output of the commands can be piped to files, and those files will be stored on the server you run the ssh command on. backupfile=$(date +%Y%m%d).sql ssh otherserver.example.org 'pg_dump --options...' >$backupfile |
thanks a lot!
everything works fine except the password. I still have to type it. What could be the problem? |
Hi again.
Here's a better guide on how to set it up: http://www.debian-administration.org/articles/152 |
thanks...now everything works as I want
|
Hi again,
I have a little Problem with this script again. I inserted the commands for openVPNc and it works fine when I run it manually. But if I want to run the script through a cronjob it creates the file but without any content. I only get the following error: Code:
vpnc-connect: command not found Can anyone help me? Code:
#!/bin/bash |
Make sure you include full path to your binaries such as vpnc-connect, find, and vpnc-disconnect in your script when running it as a cronjob as cron env is very limited.
|
When I change the lines in the script so that there are the full paths to the commands I get the following error:
Code:
etc/vpnc/vpnc-script: line 97: ifconfig: command not found Code:
# start VPN |
Ok, now I got it......it works fine and it was realy a missing $PATH in my crontab. With the following lines included it works.
Code:
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin |
All times are GMT -5. The time now is 07:16 AM. |