opus
July 25th, 2003, 01:11
That will scp a file to another machine?
If so, how would I get around entering the password manually?
What I am trying to do is this:
I backup my server nightly and copy it to a seperate HD. I would then like to scp the .tar.gz to this machine...just incase the wheels come off my server.
I am open to suggestions if this wont work.
frisco
July 25th, 2003, 02:24
Use keys.
Let's say server1 is server you are backing up as user1, server2 is other server as user2.
[code:1:436b012735]
#On server2 as user2:
ssh-keygen -t rsa #when asked, do not enter a password
cd $HOME/.ssh
mv id_rsa.pub authorized_keys
scp id_rsa user1@server1:.ssh/
#Then on server1 as user1:
scp -i $HOME/.ssh/id_rsa file.tgz user2@server2:/backup/dir/ #you won't be prompted for passwd.
[/code:1:436b012735]
Depending on exactly what you're doing, you may be interested in using rsync.
Depending on what version of FreeBSD you're using, you may be interested in using snapshots with mksnap_ffs (think db, minimum downtime).
opus
July 25th, 2003, 10:48
OK....ummmm, that is a bit over my head. Maybe you can explain it a little? Here are the exact details:
I want to scp copy /data/serverfiles/serverbackup/weekly.tar.gz which is on 192.168.2.23
over to
/~pete/backup which is on 192.168.2.210 by using cron....and not being prompted for a password.
As you can tell, I have done nothing like this before, which is why I am not quite understanding what you are telling me.
frisco
July 25th, 2003, 11:24
[code:1:c66373c79c]
#On 192.168.2.210, run the following commands as user pete:
#generate an ssh key using rsa
ssh-keygen -t rsa
#
#you now have a public key called id_rsa.pub and a private key called id_rsa.
#the public key is placed on the server you will be ssh'ing into, the private
#key is placed on the server you will be ssh'ing from (scp uses ssh for
#transport). We need to rename the public key to 'authorized_keys' so
#that sshd will recognize it for that account.
cd $HOME/.ssh
mv id_rsa.pub authorized_keys
scp id_rsa backupuser@192.168.2.23:.ssh/
#Then on 192.168.2.23 as backupuser:
#we now can use that private key to ssh/scp into 192.168.2.210 w/o using
#a password. You can put a command like this in cron.
scp -i $HOME/.ssh/id_rsa /data/serverfiles/serverbackup/weekly.tar.gz pete@192.168.2.210:backup/
[/code:1:c66373c79c]
Read through ssh-keygen and ssh manpages, and try using the commands i listed. You can safely ignore the rest of this post.
I mention rsync b/c it will incrementally backup target files to a backup sever. In other words, when only one file changes, it only copies over that one file. If you have gigs upon gigs of data, this is a real time saver.
I mention snapshots b/c these are handy for maintaining consistency in files. A snapshot of a filesystem is a filesystem which has frozen in time all the data on the target filesystem. Let's say you have a database running on its own partition, /database. If the db is running, you backup the partition, then restore the db from that backup, the db will have problems since its datafiles will have been changing while the db was running. With a snapshot, you can bring the db down, take a snapshot of the filesystem (which only takes a few seconds), start the db again, and backup the snapshot fs instead of the actual fs. The snapshot will contain the files as they were when the db was stopped, so there is no consistency problems. (yes i know modern db's have other means of accomplishing the same thing, but snapshots can be an alternate method, which for important db's and given the minimum time requirements can be a Good Thing). Snapshots work by recording the changes made to the target fs, and then when you read from the snapshot, the changes are subtracted from the actual fs, giving you the original fs. Solaris >=8, Veritas FS, FreeBSD >=5 and some linux VM's have snapshot capability. I imagine the other enterprise unix OS's do too, but i dont get to work with those.
opus
July 25th, 2003, 11:58
Very good, that makes sense now. I totally forgot about private and public keys. I will read more on this too.
Many thanks!!!
soup4you2
July 25th, 2003, 12:01
Getting Started With SSH:
http://bsdhound.com/modules.php?name=News&file=article&sid=74
opus
July 25th, 2003, 13:34
Frisco,
Let me ask you this:
I have a http server/mailserver just here at home. I run a few of my websites on it and 4 users for mail.....nothing big. Like I said, I back it up every evening so incase I have a wreck, I still have my data. Problem is, if my HD goes poop, I have to reinstall everything......very time consuming.
Would I benefit by using rsynch or snapshots better than what I am doing? Would it be more easily restored to a new HD?
Can you point me to how to do this. I am willing to read, just not sure where to find what I am looking for.
frisco
July 25th, 2003, 14:01
Backup data that doesn't change once. Backup data that changes often on a regular basis. You can use the same method for both.
Essentially, all you need to install a system is the bootblocks,your partitioning scheme, and the stuff that's currently on your filesystems. That is, as long as you have a full backup of everything, you should be able to wipe the disk, boot off recovery media, partition disk, restore data and reboot. Should be the same system you last had. I don't know if there are any FreeBSD utilities that make this easier, anyone else know?
I usually just stick to backing up /etc /root /var and /home. That is, all configuration files, all home dirs, all logs. Maybe some other dirs depending on OS. Binaries are easy to install, they're just base OS or packages. It's the configuration and the data that takes a while.
opus
July 25th, 2003, 14:17
True.....
I was thinking about building a new server and copying over my backed up data. I could just install the OS and base packages and copy in my data I guess. It would be nice though to be able to just copy everything at once and ....presto!
opus
July 25th, 2003, 16:53
Just been reading around about using 'dump'. Read the man and handbook. I am looking for something simple now where I can dump from 1 machine to another over ssh.
I tried which was in the handbook:
/sbin/dump -0uan -f - /usr | gzip -2 | ssh1 -c blowfish \
pete@192.168.2.210 dd of=/mybigfiles/dump-usr-l0.gz
Can this be simplified so it works? What is the "dd of=mybigfiles/dump_usr.gz" part about?
I assume this is dumping the /usr partition? I was wanting to put this in ~/dump dir
elmore
July 25th, 2003, 17:33
If you want some ideas about using dump, here's the backup script that runs on SE every night. I'm dumping to tape but this script could be easily modified to dump to just about anything.
[code:1:940a374481]
#!/bin/sh
echo " Starting Full Backup..."
/sbin/dump -0au -f /dev/nrst0 /dev/rsd0a
/sbin/dump -0au -f /dev/nrst0 /dev/rsd0d
/sbin/dump -0au -f /dev/nrst0 /dev/rsd0e
/sbin/dump -0au -f /dev/nrst0 /dev/rsd0f
/sbin/dump -0au -f /dev/nrst0 /dev/rsd0g
/sbin/dump -0au -f /dev/nrst0 /dev/rsd0h
echo
echo -n " Rewinding Drive, Please wait..."
mt -f /dev/rst0 rewind
echo "Done."
echo -n " Printing out backup file List, Please Wait..."
echo -n
/sbin/restore -tvs 1 -f /dev/rst0 > /tmp/backuplist
/sbin/restore -tvs 2 -f /dev/rst0 >> /tmp/backuplist
/sbin/restore -tvs 3 -f /dev/rst0 >> /tmp/backuplist
/sbin/restore -tvs 4 -f /dev/rst0 >> /tmp/backuplist
/sbin/restore -tvs 5 -f /dev/rst0 >> /tmp/backuplist
/sbin/restore -tvs 6 -f /dev/rst0 >> /tmp/backuplist
echo "Done"
echo -n "Rewinding Tape, Please Wait..."
mt -f /dev/rst0 rewind
echo "Done"
[/code:1:940a374481]
I know this isn't exactly what you're looking for but it might give you some ideas about how to craft your own backups. Good Luck!
Essentially I just dump to tape every night print out the list to a file in /tmp (yes this file is BIG) and then when I log in I just check the file in /tmp to make sure things are going properly. Obviously this script runs after the daily script with deletes files in /tmp.
Again I hope this gives you some better idea of how to use dump in a practical manner. :)
opus
July 25th, 2003, 19:40
Elmore,
Explain this part to me:
(I know this part) /sbin/dump -0au -f (what is /dev/nrst0?) /dev/nrst0 (I assume this is your tape drive?)/dev/rsd0a
So if I were to do this using ssh:
/sbin/dump -0au -f /usr/ ssh pete@192.168.2.210: ~/backup
Would that give me a dump uf /usr and ssh it to ~pete/backup?
opus
July 25th, 2003, 22:27
Got it!
/sbin/dump -0uan -f - /usr | gzip -2 | ssh pete@192.168.2.210 dd of=/usr/home/pe
te/backup/dump
Not sure if this is the best method....but it worked. :D
opus
July 26th, 2003, 17:06
Ok, what I have done is dumped /, /usr/var/tmp /dev and stuck them on CD (dont know why I did /tmp). Everything I need was dumped. Is this sufficient to do a proper restore? From what I have read, I need to install a minimal clean on a new install. I cant then do the restore....correct?
I just hate to have to rebuild my server completely if it falls apart.
elmore
July 26th, 2003, 19:44
Well, that looks good to me, yeah if your server crashes you'll have to do a base load again, but you should be able to pull everything else off your dump. Glad you got this working petie! I love the feeling I get when I finally work through some problem. What A rush huh!
:D:D:D
opus
July 26th, 2003, 20:43
Yeah, but I haven't a clue how to restore it, but by golly I've got it should I ever need it!! :shock: