View Full Version : Unix People Please... tar over scp
madamimadam
Aug 19, 2003, 11:07 PM
Hey, we've been working on a script here for our daily back up which includes:
tar -czf Destination /Users
scp Source Destination
rm Source
The obvious problem with this is that it is tar.gzing to the source machine and then sending to the server and certain machines are running out of memory (inc. mine since I have a lot of AACs).
What I would like is:
tar -czf user@IP:/Volumes/BackUp/backup.tar.gz /Users
I have been told that I can get something like that to work using standard output with a pipe and ssh command but I can't for the life of me get it to work.
visor
Aug 20, 2003, 06:40 PM
I'm to lazy to try, but have you tried
tar -cz bla |scp user@bla
the -f flag references to a file resource, i think skipping the f would put it to standard out, or the pipe respectively.
zimv20
Aug 20, 2003, 07:05 PM
Originally posted by madamimadam
certain machines are running out of memory [...]
tar -czf user@IP:/Volumes/BackUp/backup.tar.gz /Users
by "memory" i assume you mean disk space?
is "BackUp" the name of a drive on your server? if so, and you've got it mounted to your client machine, you can do:
% tar czf /Volumes/BackUp/backup.tar.gz /Users
visor
Aug 20, 2003, 07:35 PM
can't get the hang of tar now, but here is something that will work if you cannot mount your server (which would of course be best)
gzip -c files* |ssh 192.168.1.12 "cat >/Users/bla.gz"
where -c menas write to stdout.
If you can persuade tar to write to stdout, it should work likewise.
madamimadam
Aug 20, 2003, 09:53 PM
Thanks for the info
Here is what I am doing now until I work out the best solution that copies resource forks
#!/bin/sh
NAME=`hostname`
tar --bzip2 -cf - /Users | ssh backup@192.168.0.4 "cat > /Volumes/BackUp/$NAME.tar.bz2"
zimv20
Aug 20, 2003, 10:42 PM
Originally posted by madamimadam
tar --bzip2 -cf - /Users | ssh backup@192.168.0.4 "cat > /Volumes/BackUp/$NAME.tar.bz2"
how are you getting around the ssh login step?
madamimadam
Aug 20, 2003, 10:50 PM
Originally posted by zimv20
how are you getting around the ssh login step?
Well, i have not implimented it yet (running manually) but what I'm doing today is creating a text file called authorized_keys in the .ssh folder of the backup server.
I originally just made the user backup one that could log in but had no home folder but by giving it a home folder I am able to add that file and not worry about the log ins.
Sorry, forgot to specify, in the authorized_keys file you add the keys of all the machines that will be logging in. The way I like to find the keys is to simply ssh into all the machines that will be backed up from the back up server. When you ssh into a machine you have to authorise the machine you are logging into and it saves the key in the known_hosts file which is also in the .ssh folder. I'm just going to do a simple copy and paste job from that file.
madamimadam
Aug 21, 2003, 09:10 PM
To find client key and add to file:
sudo ssh-keygen -t dsa -f /private/var/root/.ssh/id_dsa -C "Comment"
To add this key to authorized_keys:
cat /private/var/root/.ssh/id_dsa.pub | ssh root@192.168.0.4 "cat - >> /Users/backup/.ssh/authorized_keys"
To turn on public key authorisation on the server:
echo "PubkeyAuthentication yes" >> /etc/sshd_config
obviously needs to be run as root on the server
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.