Slackware This Forum is for the discussion of Slackware Linux.
|
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
02-04-2006, 11:53 AM
|
#1
|
LQ Newbie
Registered: Jan 2006
Distribution: Ubuntu 606
Posts: 9
Rep:
|
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.
|
|
|
02-04-2006, 12:00 PM
|
#2
|
Senior Member
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507
Rep:
|
Tar should do. Something like `tar cjf /backups/home_bubba.tar.bz2 /home/bubba`. See `man tar` for all the options.
|
|
|
02-04-2006, 12:03 PM
|
#3
|
Member
Registered: Sep 2003
Location: UK
Distribution: I use 'em all ;-)
Posts: 275
Rep:
|
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
|
|
|
02-04-2006, 12:18 PM
|
#4
|
LQ Newbie
Registered: Jan 2006
Distribution: Ubuntu 606
Posts: 9
Original Poster
Rep:
|
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?
|
|
|
02-04-2006, 12:21 PM
|
#5
|
LQ Newbie
Registered: Jun 2005
Distribution: Slackware 10.2
Posts: 19
Rep:
|
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
|
|
|
02-04-2006, 12:22 PM
|
#6
|
LQ Newbie
Registered: Jun 2005
Distribution: Slackware 10.2
Posts: 19
Rep:
|
Wow, seems like a lot of ppl beat me to the punch!
|
|
|
02-04-2006, 12:24 PM
|
#7
|
Senior Member
Registered: Oct 2004
Location: Luxemburg
Distribution: Slackware, OS X
Posts: 1,507
Rep:
|
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.
|
|
|
02-04-2006, 12:37 PM
|
#8
|
Member
Registered: Dec 2005
Location: Chicago
Distribution: Fedora and Redhat
Posts: 86
Rep:
|
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
|
|
|
02-04-2006, 01:39 PM
|
#9
|
LQ Newbie
Registered: Jan 2006
Distribution: Ubuntu 606
Posts: 9
Original Poster
Rep:
|
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.
|
|
|
All times are GMT -5. The time now is 03:06 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|