LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Backup setup (https://www.linuxquestions.org/questions/linux-software-2/backup-setup-140386/)

robhargreaves 01-30-2004 11:31 AM

Backup setup
 
One thing I would like to be able to do is to set up my pc to back up automatically for me all of the files I have in my /opt/ directory and add them to my other hard disk on a partition I will create called backup. I will call the partition backup so it will be at /usr/backup

I have been putting programs in here before they have been compiled onto the system. I have created a directory called system here too. I use this to keep in my files downloaded such as kernel sources previously downloaded and files for the system from intel, creative soundblaster drivers.

If I have got quite a bit of room on the drive is it a good idea to backup some of my other os files too?? which ones do you recommend I add to this backup?

I believe i should be using cron or the crontabs is that true?? If so which one? bearing in mind I have got KDE3.1, Slack 9.1.

Thanks guys for the help it will be a thinhg off my mind if I can automate backups of my data like I used to do in windows.

Rob

homey 01-30-2004 11:35 AM

Here is an example setup which I have......

Creating a cron job to backup the /home directory every day at 11:00pm.

mkdir -p /mnt/backup
mount /dev/hdb1 /mnt/backup -t ext3

Add a line to fstab to mount it everytime you boot.
/dev/hdb1 /mnt/backup ext3 defaults 0 0

Make a file called /mnt/backup/backup.job
#!/bin/bash
filename=`date '+%m%d%y'`
tar -cvzf /mnt/backup/${filename}.tar.gz /home

Run these commands:
chmod +x /mnt/backup/backup.job
export EDITOR=vi
crontab /etc/crontab
crontab -e

Add a line to your personal crontab.....
00 23 * * * /mnt/backup/backup.job

Save the changes with the command: :wq!

robhargreaves 01-30-2004 12:28 PM

Thanks Homey I will give it a shot

you said -

Make a file called /mnt/backup/backup.job
#!/bin/bash
filename=`date '+%m%d%y'`
tar -cvzf /mnt/backup/${filename}.tar.gz /home

What are variables for filename = (the syntax for hostname,time etc)

Run these commands:
chmod +x /mnt/backup/backup.job
export EDITOR=vi
crontab /etc/crontab
crontab -e

What are you doing in lines 3-5 here?

Add a line to your personal crontab.....
00 23 * * * /mnt/backup/backup.job

I guess 00 06 * * * /mnt/backup/backup.job

is for 6am but what are the other 00's and ***'s for and where is my personal crontab? cron.daily, cron.monthly? etc

homey 01-30-2004 01:04 PM

filename=`date '+%m%d%y'
This gives the current date to the filename so you can keep track of them.

chmod +x /mnt/backup/backup.job
This makes the backup.job executable so cron can run it.

export EDITOR=vi
crontab /etc/crontab
crontab -e
This just makes it automatically open the vi editor when you make the next statement. You only need to do this when setting it up.

I guess 00 06 * * * /mnt/backup/backup.job

Yep, that's for 6am and "00" is for no minutes. If you had a * in the minutes column, the job would run every minute of the 6am hour. :(

"is for 6am but what are the other 00's and ***'s for and where is my personal crontab? cron.daily, cron.monthly? etc"

The other *'s are for day, week and month
This just one way of doing things, as usual in Linux, you can use other methods. One is to put the script into the /etc/cron.hour folder and then edit the /etc/crontab to include the 06 line.
You also can set it up using Webmin.

robhargreaves 01-30-2004 01:17 PM

I see. It is much faster to just use the ***'s to specify when you want the jobs doing then you dont have to mess about with the other cron folders.

homey 01-30-2004 01:24 PM

Yep, that just says to run the job at

00 Minutes, 6am hour, every day, every week and every month.

bax 10-19-2006 05:16 PM

I know this is an old thread but I'd hate to start a new one. How do i setup this up to overwrite each previous backup?

trickykid 10-19-2006 05:29 PM

Quote:

Originally Posted by bax
I know this is an old thread but I'd hate to start a new one. How do i setup this up to overwrite each previous backup?

Well if you place these in their own directory, just add a rm -rf /path/to/file.tar.gz

Or why not keep an actual retention of a week with something like:

find /path/to/*.tar.gz -t file -mtime +7 -exec rm -rf {} \;

matthewg42 10-19-2006 05:32 PM

Don't mount your backup directory in /usr. /usr is for read-only data according to the filesystem hierarchy standard.

If you only temporarily mount the device (i.e. while making or restoring from backups), mount it at /mnt, Else the proper place is probably /var/backups.


All times are GMT -5. The time now is 02:44 AM.