LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 02-04-2006, 11:53 AM   #1
shado40
LQ Newbie
 
Registered: Jan 2006
Distribution: Ubuntu 606
Posts: 9

Rep: Reputation: 0
Question Script writing question from a noob


I apologize first for my gross ignorance. I would like to write a script that would allow me to automate a backup of a specific directory. I know I can use cron to schedule the script to run, but the only information I have on how to write the script is from a RedHat book. It says I need a program called arch_data which isn't in slackware apparently. It also says I should reference the functions located in the /etc/init.d directory, which also doesn't seem do be in slack. What I want to do is have a dir (ie /home/bubba) archived and compressed to an alternate dir (ie /backups) and have it scheduled to run once a week, how would I do this in slackware? This is only my second time trying to write a script so I am really in the dark.
 
Old 02-04-2006, 12:00 PM   #2
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
Tar should do. Something like `tar cjf /backups/home_bubba.tar.bz2 /home/bubba`. See `man tar` for all the options.
 
Old 02-04-2006, 12:03 PM   #3
Dudydoo
Member
 
Registered: Sep 2003
Location: UK
Distribution: I use 'em all ;-)
Posts: 275

Rep: Reputation: 38
Create a file called 'backup.sh' or whatever you want:

<-- Beginning of file -->

#!/bin/bash

SRC=/home/bubba
DEST=/backup

tar -cvzf $DEST/backup.tgz $SRC

<-- end of file -->

Make it executable by issuing:

$ chmod +x backup.sh

Edit your cron list and add the job - (see man 5 crontab):

$ crontab -e
 
Old 02-04-2006, 12:18 PM   #4
shado40
LQ Newbie
 
Registered: Jan 2006
Distribution: Ubuntu 606
Posts: 9

Original Poster
Rep: Reputation: 0
Wow, you guys make that look easy. I again apologize for the stupid questions, but thanks a million. This forum has been a life saver on more than one occasion. Now I see that I probably wouldn't even need a script to make it work, but could it be done where it would make a seperate file each time instead of always writing over the same file?
 
Old 02-04-2006, 12:21 PM   #5
Zaelryn
LQ Newbie
 
Registered: Jun 2005
Distribution: Slackware 10.2
Posts: 19

Rep: Reputation: 0
How long have you been using GNU/Linux? For the purpose of this reply, I'll assume you're very new.

You need to use cp to copy /home/bubba to wherever, do "cp --help" or "man cp" and learn about cp. tar will roll up your copied directory tree into one big file, do "tar --help" or "man tar" and learn about tar, tar has lots of switches and options that I don't have memorized. gzip will compress the tar file, "do "gzip --help" or "man gzip" and learn about gzip, gzip also has a good number of switches and options to learn about. "man crond" will teach you about cron, a program that runs tasks according to a schedule. I've never used cron before, so I fear I can't be of much help to you there, but if crond's man page doesn't help you, let me know, I'll try to do some research for ya. Once you know the arguments to feed to cp, tar, and gzip, then you write a script (which I can't imagine will be more than a few lines) to do the copying, tarring, and gzipping. Then you tell cron when and how often to run the script.

I hope I can help you, and I hope others more knowledgeable than myself will also come to your aid. I've been using GNU/Linux for about 8 months now, but I've never had the need to write a script
 
Old 02-04-2006, 12:22 PM   #6
Zaelryn
LQ Newbie
 
Registered: Jun 2005
Distribution: Slackware 10.2
Posts: 19

Rep: Reputation: 0
Wow, seems like a lot of ppl beat me to the punch!
 
Old 02-04-2006, 12:24 PM   #7
uselpa
Senior Member
 
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507

Rep: Reputation: 47
Try something like:
Code:
tar cjf /backups/home_bubba_`date +%Y%m%d-%H%M%S`.tar.bz2 /home/bubba
Watch for the backticks (`), they're important.
 
Old 02-04-2006, 12:37 PM   #8
sipsipi
Member
 
Registered: Dec 2005
Location: Chicago
Distribution: Fedora and Redhat
Posts: 86

Rep: Reputation: 15
For making unique, day/date specific backups, i do the following:

tar -cvf /directory/to/backup backupfile_`date +%Y%m%d`.tar

Checkout the man page for date. this output looks like backupfile_20060204.tar and so on
 
Old 02-04-2006, 01:39 PM   #9
shado40
LQ Newbie
 
Registered: Jan 2006
Distribution: Ubuntu 606
Posts: 9

Original Poster
Rep: Reputation: 0
Alright. Thanks again, you all have been very helpful, I am glad to say more often than not the solutions to the problems I run into with linux are much simpler than I expect them to be. I knew about tar before but it never occured to me to use it for this purpose.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
noob bash script question babag Programming 9 04-30-2005 03:25 AM
Linux Noob writing simple application that needs to query SQLServer radikaled Linux - Newbie 1 01-18-2005 12:26 PM
help writing script willinusf Programming 7 07-20-2004 12:37 PM
script noob spuppett Linux - General 1 04-27-2004 10:48 PM
Complete noob question from a noob noob_hampster Linux - Software 2 09-04-2003 01:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration