Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Much of this same functionality is present within the 'logrotate' script (auto-renumbering of old files, with the added potential of gzipping the output), if you would like to look at the man page for some suggestions.
Secondly, what language is your script written in? There are many ways to accomplish the above, be it in perl, bash, or some other language. Simple pattern matching (read up on 'regular expressions') can return a filename to the rest of your script (and testing for age is a trivial task).
$suffix will hold the value '0', you then just add one to this number. $prefix will contain the rest of the name. You can integrate this into a for loop to rename all the files on a given directory in this fashion:
for file in *
#calculate prefix and sufix
#add 1 to suffix
#rename the current file
I also need to add to my script something that will gzip all the backed up directories when the .6 is reached into one gzip file with the date of the .0 in the name, like below:
This check could be as sophisticated as you wish, however a simple way is to "start" for *.6, if there's any file that complies that condition then do <something>.
stat *.7 >/dev/null 2>&1 && echo true
Of course here instead of "echo true" you would call a custom function or something else that will compress the backup for you.
I know its a challenge but there are some incredibly smart people on here that i think can help me. Thanks!
If the date is going to be part of the file name, then you can use the tricks I told you above to cut it into pieces and extract the date into a variable, then use it to compose the name of the final tarball.
I hope these hints are useful. Ask back if you need more info on any of these, I guess it's a bit daunting at first. I can help you but I don't want to give the script straight away because that won't help you with learning bash. I also recommend reading the bash man page (yeah, I know it's boring) and googling for the "advanced bash scripting guide". Regardless of the title it's suitable for beginners as well.
Actually, it helps me more to see how the script looks because i seem to learn best when i see the results of the question and reverse engineer it to see how it all works. Honestly, im kind of lost with your explanation but seeing how it would script out would help understand it more.
It works good in a way, one problem though, it increments EVERY thing by one, scripts, txt files, etc.... Anyway to do it just for directories or by directories beginning with the name file?
Other than that, looks great!
Also, were you able to figure out part 2 to my original question, how to tar everything up into one big tar file with the date of the .6 file when the 7th backup is due to run? (please see my original post for the actual details