Making A DB Backup And Send It To Another Server

Hello everyone;

At this time I need to make a sh script to make a db backup an send it to another server.

Thinking about this, I think I have to:
1.- Make a connection beetween the servers without password
2.- The scrip must to do:
a.- Make the mysqldump
b.- Put it in a gzip file
c.- Send througth scp the gzip file and ONLY when the copy has done the script have to delete the files that are 3 days old.

Could you help me with this?

Do you consider that is a good idea or you have a better one?

Thanks in advance.


Similar Content



How To Copy File From Remote Host To Local Host Then Delete From Remote Host

I have an expect script to SSH to a remote host and obtain some user inputs and information about the server/network configuration. The responses are saved in a text file that I then need to copy to my local host so that I can read the lines into variables for use in the parent shell script.

Is there a way to do this without needing to enter the username and password for the local host to use function scp? I have tried the following in my expect script to no avail:
Code:
spawn scp $usr@$host:$flnm .
expect {
	-re "(.*)assword:" { 
		send -s "$pswd\r"
	}
}

I have also tried to directly scp the file and enter the username and password to try to debug the issue, and that doesn't work either:
Code:
spawn scp file.txt user@host:file.txt
expect {
	-re "(.*)assword:" {
		send -s "password\r"
	}
	"you sure you want to continue connecting" {
		send -s "yes\r"
		exp_continue
	}
}

In both scenarios I have used exp_internal 1, and there are no errors. But I do not end up with the file on my local host.

Following the copy, I would like to delete the file from the remote host. Any suggestions on how to accomplish this?

Need Commands For The Following Scenario

scenario: two servers A and B are connected together
server A can not send a file name F directly to server B
server B can send anything to server A

How can we copy or move the file F from server A TO B with all file permissions

Thanks for your kind help

Cygwin Rsync Script Copying File Incorrectly

I am trying to write a simple test script that executes a single rsync call. Once I get the syntax right, the script will be expanded to incorporate several rsync instructions to save me time.

I'm using a Cygwin Terminal on Windows 7 to run Rsync.

The script is called "backup" and I call it from the cygwin terminal using "./backup". Have used chmod to make it executable.

When I execute the rsync instruction as a standalone instruction at terminal prompt, the file copies to the target folder perfectly.

However, when I try and drop the same instruction into a script, it copies the file over from it's original file name "mvi_1840.mov" to a file with the name "." -- literally a single period. I can rename the file to a .mov file and it works fine but naturally, I don't want to have to do this.

The one other thing I will mention is that the file is located in the /home/"username" directory in cygwin vs /bin. But I would not think that this would make a difference.

I have pasted the contents of the script file below:
Code:
#!/bin/bash
    rsync.exe -rltDvP --exclude "System Volume Information" --exclude
 "RECYCLER" --exclude=\$RECYCLE.BIN --delete "/cygdrive/c/users/<USERNAME>
/desktop/mvi_1840.mov" "/cygdrive/c/users/<USERNAME>/desktop/test/"

Any help would be greatly appreciated!

Thanks

Dd Command For Backing Up Linux OS..am I Doing This Right?

hey guys, I understand how dd works. Ive been researching on it and I see that
if="" is the source of what I want to copy
of="" is that target that I want to send the back up to

so, what i am trying to do it copy my hard drive from saturn server: /dev/sda1 over SSH to my backup server skyline.

so [saturn harddrive /dev/sda1] -----backup---> [skyline:/backup/directory]


this is the command I am using
sudo ssh willc86@skyline "dd if=/dev/sda1 " | dd of=/backup/saturn.img

however, it is saying failed to open /dev/sda1/ : permission denied and I am runnign as root. any idea why?

thanks a bunch guys!

How To Shrink A Large Audio Ogg File

I would like to learn how to create a zip file. The word zip file is a Windows/Microsoft word. I do not know what word is used in Linux OS.
What I am trying to do is send a copy of an internet radio show. The show is two hours long. When I try to attach the audio file to an email. I am told the file is too large.
I have permission from the host of the radio show to make a copy and send it to a friend.

Script Automatic Send Email Using Crontab

Hello,

I have server but it all hardening.i can't install mailx and sendmail. How could i do script to automatic send email to my mailbox using crontab?

any idea guy.

Thanks for the help.

Samhan

How To Return From Shell 'read' Command Passed In Expect Script?

I have a shell script that calls an expect script I wrote to ssh login to another host and get user input regarding that host's network configuration. I pass four arguments to the expect script: the remote host ip address, the username, the password, and the list of commands to run. My expect script is below:

#!/usr/bin/expect
# Usage: expectssh <host> <ssh user> <ssh password> <script>

set timeout 60
set prompt "(%|#|\\$) $"
set commands [lindex $argv 3];

spawn ssh [lindex $argv 1]@[lindex $argv 0]

expect {
"*assword:" {
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

"you sure you want to continue connecting" {
send -- "yes\r"
expect "*assword:"
send -- "[lindex $argv 2]\r"
expect -re "$prompt"
send -- "$commands\r"
}

timeout {
exit }

expect -re $prompt
send -- "exit\r"
}

The script runs well, except that if I send a command such as 'read' that requires user input, the script does not continue or exit after the user presses enter. It just hangs.

The commands I pass to the expect script and it's call are as follows:
SCRIPT='hostname > response.txt;netstat -rn;read net_card?"What is the network interface card number? " >> response.txt; read net_mask?"What is the subnet mask? " >> response.txt'

/usr/bin/expect ./expectssh.exp $hostip $usr $pswd "$SCRIPT"

Any suggestions on how I can pass a command to my expect script that requires user input without it hanging?

On a side note because I know it will come up - I am not allowed to do key-based automatic SSH login. I have to prompt for a username and password, which is done from my main shell script.

Thanks for any suggestions and help you can provide!

Gzip -r -c Directory > Archive.gz

SUSE 11. I have issued the command "gzip -r -c directory > archive.gz" over a complete directory tree. I've got no errors or warnings. I can decompress the gz file also without errors, but what I get is a single file which is the concat of all of the original files, including binaries, without posibility of splitting them into the original ones.

I suppose I've lost my files, no?.

Secondary question: why does gzip let me issue that destructive command?

Regular Expression In Expect Script To Prevent Printing To Screen

Hello, I have an expect script where I ssh to a remote host to determine the network configuration and get from the user the network interface card that should be used. From their response, I determine the subnet mask and save the information to a text file that is later transmitted back to my local host. This is all so that I can set up virtual IP aliasing and verify that the physical IP address of the local and remote host are on the same subnet prior to continuing with the setup. I am running the script on Linux, with expect version 5.45.

The code itelf works just fine, but I'm having some issues with how it displays on the screen. As you'll see below in the example, the default system prompt displays, as does the user input command that I'm sending to the shell from the expect script.

Is there a regular expression or something that I can write to prevent the prompt and command that I'm sending from printing to the screen? I know that it should be suppressed if I have an expect command following the Code:
send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0):   '\r

command, but everything I have tried for strings and regular expressions to expect causes the netstat -rn output to not show up all of a sudden. I'm new to expect, so I'm not really sure why this is happening.

I would really appreciate any help/suggestions. Thanks for your time!

Part of the Script Code:
Code:
expect {
   -re $prompt {   ;# Send individual commands and get user input
        set timeout -1
        
        # Get partner hostname and put in vipsetup.txt file
        send -s "hostname > vipsetup.txt\r"  
        expect -re $prompt
        
        # Display the network routing info for the user and prompt for 
        # network interface card number
        send -s "print \"The network routing table for the $ptner server is displayed below:\n\" ; netstat -rn \r"
        
        expect -re "\r(.*):\r"
        send -s "\nread n_card?'Enter the network interface card number for this server (i.e. eth0):   '\r"
        interact "\r" return    ;# Wait for user input from read command
        send -- "\r"
        send -s "echo \$n_card >> vipsetup.txt\r"  
        
        # Obtain subnet mask information for partner based on network 
        # interface card number being used
        send -s "msk=\$(cat /etc/sysconfig/network-scripts/ifcfg-\$n_card | grep NETMASK)\r"
        send -s "msk=\$(echo \${msk#NETMASK=})\r"
        send -s "echo \$msk >> vipsetup.txt\r"
    }
    timeout {
        send_user "Connection to host $hostip timed out."
        exit 6 
    }
    eof {
        send_user "Connection to host $hostip failed."
        exit
    }
}


Script Output:
Code:
The network routing table for the PRIMARY server is displayed below:
 
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.105.65.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0
0.0.0.0         10.105.65.1     0.0.0.0         UG        0 0          0 eth0
 [root@remotehost root]$
[root@remotehost root]$ ber for this server (i.e. eth0):   '              < 
Enter the network interface card number for this server (i.e. eth0):   eth0

Script To Find The File Creation Time Is More Than Ten Minutes

Hi All,

Im trying to create a script which checks the creation time of a file and if it is more than ten minutes, send out an alert.

For ex : Creation date of file is 10:30 AM
current time is 10:45 AM

Then send an alert/ message.

This is the script i wrote below :

Code:
#!/bin/ksh

filename="/apps/log/file.txt"

if [ -f "${filename}" ]
then
        createTime=`ls -lad "${filename}" | awk '{print $8}'`
        echo "$createTime"
        currentTime=`date '+%M'`
        echo "$currentTime"
        DIFF=$(( $currentTime - $createTime )) 
        echo "$DIFF"

else

        exit 1

fi

I am getting syntax error on the subraction when i try to run this script . I can understand that creation time and current time is in different format thats y this error throws, but i dont know how to rectify it .

I need to find out if the file creation time is more than ten minutes.

Please help me in achieving this output.