LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 01-27-2013, 10:05 AM   #16
KirkD
Member
 
Registered: Oct 2007
Posts: 58

Original Poster
Rep: Reputation: 15

I got the remove oldest piece working. I added this just below the Remove oldest backup line:

Code:
ssh root@$NAS \
"cd $DestDir \
&& ls -t | sed -e '1,"$n"d' | xargs -d '\n' rm -rf"
My current script is listed below.

Next is to set it up as a cron job. The only thing outstanding is the use of files to specify included/excluded directories and files. (Question 1, above).



Code:
# —– Edit these variables to suit your environment —–

n=60                                       #Number of backups to retain
NAS=192.168.0.185                          #IP address or resolvable hostname of NAS
SrcDirs="/home/keenansm/Projects /home/keenansm/Datasets"
DestDir=/nfs/Public/alfonz/Backups   #Backup destination on NAS
Date=`date "+%Y-%m-%dT%H_%M_%S"`

# —– End of edits —–

echo
echo =========================================================================
echo “Starting backup.sh…..”;
date;

# Delete the oldest backup if there are more than n backup directories.
echo
echo Removing oldest backup.
ssh root@$NAS \
"cd $DestDir \
&& ls -t | sed -e '1,"$n"d' | xargs -d '\n' rm -rf"

echo
echo Starting rsync...
# Run the Rsync command. Nice is used to prevent Rysnc from hogging the CPU.
# –link-dest creates hard links so that each backup run appears as a full
# backup even though they only copy changed blocks 
nice rsync -azv \
--link-dest=$DestDir/current \
--delete \
--delete-excluded \
--exclude=*/pics \
--exclude=*/HTML \
$SrcDirs root@$NAS:$DestDir/incomplete_backup-$Date \
&& ssh root@$NAS \
"mv $DestDir/incomplete_backup-$Date $DestDir/Backup-$Date \
&& rm -f $DestDir/current \
&& ln -s $DestDir/Backup-$Date $DestDir/current"
echo
echo =========================================================================
echo “Completed running backup.sh”;
date;
 
Old 01-27-2013, 05:58 PM   #17
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Won't '--files-from' do what you want in this case ?
 
Old 01-27-2013, 06:53 PM   #18
KirkD
Member
 
Registered: Oct 2007
Posts: 58

Original Poster
Rep: Reputation: 15
The problem with --files-from is that I still have to specify a source directory:

rsync -av --files-from=filelist.txt /somedirectory_as_source /desitnation_backup_directory

So, anything in /somedirectory source gets backed up as well. I cannot leave out the /somedirectory or rsync fails due to assuming the /destination_backup_directory is the source and no destination is specified.
 
Old 01-28-2013, 02:46 PM   #19
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Sorry, maybe I'm not understanding what you need .. here's what I was envisioning:

Code:
$ tree a
a
├── 1
├── 2
└── 3
$ cat list
1
$ rsync -av --files-from=./list a/ dest/
building file list ... done
1/

sent 52 bytes  received 15 bytes  134.00 bytes/sec
total size is 0  speedup is 0.00
You always have to specify a source directory but the list of files/directories to copy is passed in... not what you meant?
 
Old 01-29-2013, 04:25 PM   #20
KirkD
Member
 
Registered: Oct 2007
Posts: 58

Original Poster
Rep: Reputation: 15
What I find when I do this is that all of the subdirectories under the source directory get copied regardless of what is specified in the list. The alternative (that I haven't tested) is if I list all the directories I want copied as well as all those that I don't want copied. e.g.,

+ 1
- 2
- 3

I believe this will work, but the number of subdirectories I don't want copied become a very long list and I don't want to manage that for each individual machine.

At this point, I've reverted back to specifying the exact directories in the script itself. The more I think about it, this seems a good option as I don't have to manage a different file with a very long list of non-included directories. Everything is self contained, albeit a little messy.

The only outstanding issue I have now is tying the backup to shutdown. It would be great if I could have the backup script run just prior to shutdown to make sure everything was backed up. Any tips on that one?
 
Old 01-29-2013, 07:01 PM   #21
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Oh well .. works for me

I think you'll have issues trying to get a backup performed on shutdown, the system is trying to stop processes not start them and depending on your run level manager you may not be able to.
 
Old 01-30-2013, 11:38 AM   #22
KirkD
Member
 
Registered: Oct 2007
Posts: 58

Original Poster
Rep: Reputation: 15
Interesting. I'll have to play with it a bit further. It is _very_ likely I was doing something wrong.

I certainly see the point with respect to a shutdown related back up. My hope was to put the rsync request early into the shutdown queue, forcing it to complete prior to any other steps within the queue. It may be easier and safer to do this manually prior to shutting down.

Thank you again for all your help. This has certainly been educational.
 
  


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
Invalid cross-device link linuxqueric Linux - Newbie 12 02-22-2020 12:24 PM
DSL modem exploit for Cross Site Request Forgery....a link aus9 Linux - Security 1 10-01-2012 09:23 PM
Invalid cross-device link teonghan Linux - Software 0 10-31-2010 10:52 PM
GNU based c++ cross compiler unable to link c library k_taid Programming 1 06-29-2005 09:38 AM
How to find an invalid symbolic link?? zhaoyoubing Linux - General 3 08-21-2003 09:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:13 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration