Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
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.
Ok so I'm trying to automate my backup procedures. Very basic, not a lot of fuss to it. But I'm trying to deliberate on a few ideas, I dont mind researching them myself, but wanted to ask if it is possible or have seen something similar to this before.
So I've got my crontab set up like this...
30 20 * * 5 root backup
Meaning that every Friday , @ 8:30 , the backup script will execute.
The backup script is simply
cd /home/directoryname
rm backup.tar.gz
tar cvf backup.tar.gz /home/backuptargetdirectory
So it goes to the home directory, removes the old backup and then creates a new one in its place.
My question is, is there a script I can write or would it be possible to have the script name the file by date..
e.g. -- July092004_backup.tar.gz
Then at the start having it delete the one from 2 weeks ago...so if i were to ls the /backup directory and it said
rdiff is a little different than what you are saying. For backups, you would probably use rdiff-backup (http://rdiff-backup.stanford.edu/).
Basically, it creates an identical backup of your source directory the first time. Every time after that, it simply backs up the changes made to the source directory since the last backup. It also contains the ability to roll-back changes, which is what the backup is for, anyway. In this case, you would NOT delete any previous backups, but simply let them build upon each other. There are options you can use so that it will remove backups that are older than a certain date, so that you are not wasting too much space.
This method would be more space efficient than what you are currently doing (3 full backups of the directory).
for the delete part, this is a bit klugey, but it works (I think):
(using tcsh):
Code:
set lsArray=( `ls -t1 | grep backup.tgz` )
if ($#lsArray > 3)
rm -f $lsArray[$#lsArray]
of corse, the uber dangerous part of this method is that if you have anything else in your dir called *backup.tgz, it may get deleted. You can avoid that by putting your backups all in the same dir
what this does is create an array made up of the contents of your directory that contain the string "backup.tgz" sorted by date (oldest last)
if then checks to see if that array is longer than 3. if it is, it deletes the last one.
I'm sure there's a better way, but this way should at least do what you want. be careful with it though.
The above code will not work in bash, but I'm sure it's pretty close.
I am trying to make the same kind of script and backup operation as TPupAZ but there are some things i don't fully understand with the scripting and it would be great if someone could give me a little help here.
I have a folder in the /home/ directory named /important/ which contains files i want to make backup of in tar.gz format and i want the archive to end up in /home/backupdir/ i have put together a script by using the tips in this thread but it's not fully operational yet
this is how my (so called ) script looks like for the moment :
cd /
cd /home/important/
tar cvzf `date +%B``date +%d``date +%Y_backup.tgz /home/important/
cd /
cd /home/backupdir/
while (( 1 > 0 )); do
lsArray=`ls -t1 | grep backup.tar.gz`
length=`echo $lsArray | wc -w`
if (( $length > 3)); then
rm `echo $lsArray | cut -d` ` -f $length`
else
break
fi
done
Now this script sort of works 'cause it DOES put all the files in the /important/ dir into a dated .tgz archive but the archive is placed in the same directory as the files in it (/important) and I want it to end up in the /backupdir/
I probably just have made a simple mistake somewhere along the way in the script but I am just a beginner at Linux so I don't have any experience with this kind of scripting and therefore just don't know what to do
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.