Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-09-2008, 07:09 AM
|
#1
|
|
LQ Newbie
Registered: Jul 2008
Posts: 6
Rep:
|
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!!!!
|
|
|
|
07-09-2008, 12:50 PM
|
#2
|
|
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,014
Rep: 
|
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
|
|
|
|
07-09-2008, 06:09 PM
|
#3
|
|
LQ Newbie
Registered: Jul 2008
Posts: 6
Original Poster
Rep:
|
thanks a lot!
everything works fine except the password. I still have to type it. What could be the problem?
|
|
|
|
07-28-2008, 10:02 AM
|
#5
|
|
LQ Newbie
Registered: Jul 2008
Posts: 6
Original Poster
Rep:
|
thanks...now everything works as I want
|
|
|
|
08-27-2008, 05:20 PM
|
#6
|
|
LQ Newbie
Registered: Jul 2008
Posts: 6
Original Poster
Rep:
|
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
I don`t understand this error, because the script works fine, when I manually run it from the same user.
Can anyone help me?
Code:
#!/bin/bash
#
# this script is for database backup
#
# start VPN
vpnc-connect /etc/vpnc/nslu2_2.conf
# backup process
backupfile=/home/m/backup/printerdb-$(date +%d-%m-%Y).backup
ssh user@server pg_dump printerdb >$backupfile
# cleanup process
find /home/m/backup/ -mtime +21 -exec rm -r {} \;
# stop VPN
vpnc-disconnect
|
|
|
|
08-28-2008, 02:27 AM
|
#7
|
|
Member
Registered: Sep 2007
Location: SF Bay Area, CA
Distribution: CentOS, SLES 10+, RHEL 3+, Debian Sarge
Posts: 159
Rep:
|
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.
Last edited by kenoshi; 08-28-2008 at 02:31 AM.
|
|
|
|
08-29-2008, 03:10 AM
|
#8
|
|
LQ Newbie
Registered: Jul 2008
Posts: 6
Original Poster
Rep:
|
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
RTNETLINK answers: No such device
Code:
# start VPN
/usr/sbin/vpnc-connect nslu2_2.conf
or isn't this the right path??
|
|
|
|
08-29-2008, 06:00 AM
|
#9
|
|
LQ Newbie
Registered: Jul 2008
Posts: 6
Original Poster
Rep:
|
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
SHELL=/bin/sh
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 10:15 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|