Jump to content

backup script wanted


Recommended Posts

I was impressed by you guys the last time I asked for a script. I was looking for a script that can resize a whole directory of jpg's to a certain size. That was sweet. Now I have another script, or challenge, or whatever you want to call it. :D

 

I'm looking for a script that will tar both my home and etc directories, then bzip them, then push it to my server where I have a backup hard drive that can store it. I would like to put this script as a cron job so it can backup my stuff daily.

 

my current pc is lan ip 192.168.X.6 and my server is on 192.168.X.4 and the directory of my hard drive(on my server) I want to save to is called /WD160

 

thanks in advance, I wish I could code like you guys. :headbang:

Link to comment
Share on other sites

Then learn :lol:

 

Seriously, trying is the best way to learn... Anyway, does something like that suits you:

# tar cjf - /home /etc | ssh backupuser@remotehost '/path/to/remoteCommand.sh'

where ssh is configured to use keys, not passwords/passphrases for user "backupuser", and remoteCommand.sh is a script that simply dumps standard input to whatever filename is the next available (I guess you won't always overwrite the same filename)

 

I leave to you to configure cron.

 

Yves.

Link to comment
Share on other sites

tar c(compress)j(with bzip2)f(to file:) -(standard output) /etc /home |(tar'd bzip2'd result is passed on as standard input to:) ssh backupuser@remotehost '/path/to/remoteCommand.sh'

 

You'll indeed have a problem with ssh asking for a password, except if you configured ssh to work between localhost and remotehost using only private/public keys. I know that can be done, but I don't know how. The following article may help:

http://www.linuxquestions.org/questions/an...rticle&artid=79

 

Now the /path/to/remoteCommand.sh script. In its simplest form, it lives in /usr/local/sbin, and contains:

#!/bin/bash
cat >/var/backup.tar.bz2

But simple like that, the same file will get overwritten over and over again. So you may want to improve it a bit to (for example) list the currently existing backup files, and create a new unique name, so that no old backup gets overwritten.

 

Yves.

Link to comment
Share on other sites

Then learn :lol:

 

Seriously, trying is the best way to learn... Anyway, does something like that suits you:

# tar cjf - /home /etc | ssh backupuser@remotehost '/path/to/remoteCommand.sh'

where ssh is configured to use keys, not passwords/passphrases for user "backupuser", and remoteCommand.sh is a script that simply dumps standard input to whatever filename is the next available (I guess you won't always overwrite the same filename)

 

I leave to you to configure cron.

 

Yves.

 

 

thanks for breaking it down for me. Man only has so much things and it wont have symbols like the '-'

 

I need to figure out a way to avoid the password since I need it to run without me being present

Link to comment
Share on other sites

  • 2 months later...
Guest ChillyWillie

As long as your script is in a secure location with permissions 500, you should be able to insert the password in plaintext on the command line. I believe adding a "-p password' is the correct syntax, but check it in the man file. Of course, setting up the crypto keys is much much safer. If you don't forward port 22 to any of your machines, that would be isolated enough to keep nosey script-kiddies away.

 

Along the same lines, you could block FTP ports 20-21 and run an anonymous FTP server behind your firewall.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...