Unix Back Up script

stuaz

New Member
Hi All,

This is a question for the more technical script writers out there.

------

I wish to create a script that will simple Back up (tar) a certain directory, and then FTP the tar file to a different box.

------

As simple as that.

Maybe as a little bit to make it smarter would be for it to output to a file to say what time it completed? And perhaps also send an email so to say the back up completed on XXXXX.

This will be a Unix based script, so if anyone has any tips for me, had a look through Google, but they seem to be far more complicating than they should be.
 
okay....

I am no Unix wizard, but I do have a beard. This is a general script you can use that will back up said directory to a network share. then you must set up what is called cron job to automate it to run every night, every week, every month, or whatever frequency you want it to. My method is using rsync but there are other methods out there.

so here it goes, you will need to fill in your blanks to make it work.

Code:
#!/bin/bash

#this script will back up a set directory to a network share

/sbin/rsync -u -a -t /path/to/source/directory /path/to/networkshare

#please note that using the full file path is properly needed for security
#depending on distro rysnc may be installed in a different path
#most likely it lives in /bin, /sbin or /usr/bin, /usr/sbin
#if not sure execute the bash command [b]whereis rysnc[/b] to
#find your path

#now we will tell the script to mail the user when finished
#see the man page for the mail command for proper syntax

echo "Back up complete" | mail [email protected] -s back up complete

your back up has been completed

EOF

You may want to mess around with the mail command in terminal, if you type mail [email protected] it will then prompt you to start typing text. When done just hit period then enter and it will send the mail. Each distro handles syntax different but this script could at least point you in the right direction.

copy/paste it into a plain text file and name it filename.sh then set up a cron job to run it. Of course you want to test it first.
 
ooops I messed up, here is how it should look, remember you will need to plug in your file paths and your settings to make it work

Code:
#!/bin/bash

#this script will back up a set directory to a network share

/sbin/rsync -u -a -t /path/to/source/directory /path/to/networkshare

#please note that using the full file path is properly needed for security
#depending on distro rysnc may be installed in a different path
#most likely it lives in /bin, /sbin or /usr/bin, /usr/sbin
#if not sure execute the bash command whereis rysnc to
#find your path

#now we will tell the script to mail the user when finished
#see the man page for the mail command for proper syntax

echo "Back up complete" | mail [email protected] -s back up complete >> EOF

your back up has been completed

EOF
 
Back
Top