LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-19-2017, 01:56 AM   #1
MPR128
LQ Newbie
 
Registered: Jul 2017
Posts: 1

Rep: Reputation: Disabled
Rsync script to copy from USB to Unraid server


I've been given a script to install on my Unraid fileserver. The purpose of the script is to copy the contents of a USB device onto the array. It all works as it should, but I'm trying to modify it slightly to work better.

This variable is defined early on, the effect is that the script will copy everything inside a directory named DCIM on the source device.
It will also copy the contents of sub-folders, but it does not copy the sub-folders themselves.
So the result is all the files on the destination in a single folder.
The * is my attempt at getting a wildcard working.
Also, it's sitting inside a loop which isn't required, but I'll solve that later.
I've only pasted in what I think are the relevant sections, if you want to see the entire script, just click here : https://gist.github.com/ljm42/02b54ce9cc36f992515b

VALIDDIRS=("/DCIM/*/")

# loop through all the subdirs in /DCIM looking for dirs defined in VALIDDIRS
for DIR in ${MOUNTPOINT}/DCIM/*; do
if [ -d "${DIR}" ]; then
log_debug "checking ${DIR}"
for element in "${VALIDDIRS[@]}"; do
if [[ ${DIR} =~ ${element} ]]; then
# process this dir
log_local "${MOVEMSG} ${DIR}/ to ${DESTINATION}"
rsync -a ${RSYNCFLAG} "${DIR}/" "${DESTINATION}"
# remove empty directory from memory card
if [ ${MOVE_OR_COPY} == "move" ]; then
rmdir ${DIR}
fi
fi
done
fi
done
 
Old 07-19-2017, 06:19 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,018

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
please use [code]here comes your script[/code] to keep formatting.
I don't really understand, what is your problem now? How can we help you?
 
Old 07-19-2017, 06:39 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Moved: This thread is more suitable in Programming and has been moved accordingly to help your thread/question get the exposure it deserves.

Please use [code][/code] tags to encapsulate your code so as to retain the formatting.

Suggest you use find -type d to find directories versus the wildcard.
 
Old 07-19-2017, 02:06 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Welcome to LQ!

As others have already mentioned, please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.

The relationship between VALIDDIRS, MOUNTPOINT and how the wildcard might expand is not obvious. Also, the options in RSYNCFLAG are unknown from the example posted, as well as whether DESTINATION includes a trailing slash... all of which will affect the result.

If I were rewriting that script I would definitely consider use of find --type -d to find those directories as indicated by rtmistler. I would also try to simplify it to make it more human readable. If I cannot quickly understand what a block of code should be doing, I cannot know when it working and when it is not!

Good luck!
 
  


Reply



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
Script to copy files, rsync? Ruffe42 Linux - Newbie 5 04-30-2014 02:55 PM
using rsync to copy from server to local usb hard drive osakagreg Linux - General 4 09-24-2011 09:36 PM
[SOLVED] shell script to copy newly changed files with rsync genderbender Programming 15 04-22-2010 07:27 AM
Run script to copy usb drive when inserted actmnophn Linux - Newbie 1 11-19-2008 08:00 AM
Simple rsync script for backing up (multiple) pc's to a usb-disk gerben12 Linux - Server 0 05-18-2008 10:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:30 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