1

Running ubuntu 16.04

Update: I got past the error messages by double quoting the variables:

cp -ru "$line" "$destname"

But it's still not copying anything. After adding echo $? after the line above, I get 0.

Replacing cp with ls -l lists contents of the directories.

The code:

[ $# -eq 0 ] && { echo "Usage: $0 m/d/yyyy"; exit 1; }

DestDir=/media/WD_NAS_LEW/grsync

find Documents -type f -newermt $1 > mybackup.log
awk 'BEGIN{FS=OFS="/"}{NF--; print}' mybackup.log | while read line 
do
destname=$DestDir/$line
cp -ru $line $destname
done

#rm mybackup.log
echo Done

Script output -- and the files aren't copied for lines without the errors below:

$ ./mybackup.sh 8/20/2018
cp: target 'Card/Documents' is not a directory
cp: target 'Lessons' is not a directory
cp: target 'Lessons' is not a directory
cp: target 'Letters' is not a directory
cp: target 'Asia' is not a directory
cp: target 'Procedures' is not a directory
Done

Inputs: contents of mybackup.log (full path with file name):

Documents/Phone/Phone Main Memory Card/Documents/misc.doc
Documents/Lew/PFinc/Bills N Balances.ods
Documents/Lew/Trading/Market Review.odt
Documents/Lew/Trading/Trade Tools.ods
Documents/Lew/Trading/Studies & Lessons/Summary Technical Analysis.odt
Documents/Lew/Trading/Studies & Lessons/Paper calendars and diagonals.odt
Documents/Lew/Trading/Paper Trades.ods
Documents/Lew/Trading/DVL/thinkscript/Mark_Volume_SpikeSTUDY.ts
Documents/Lew/General/Essays & Letters/0 RFR.odt
Documents/Lew/General/Long Fist et al Asia/Long Tai Chi.odt
Documents/Lew/General/Technology/Backup Procedures/find files since X for manual backup.png
Documents/Kids/Carey/Carey August 2018.odt
Documents/Kids/Renee/birth certif and social Stella.pdf
Documents/Kids/Renee/Noah/Noah Confucius tenets.odt

awk output (source dir only, no trailing "/"; destination drive is Western Digital mybook NAS):

/media/WD_NAS_LEW/grsync/Documents/Phone/Phone Main Memory Card/Documents
/media/WD_NAS_LEW/grsync/Documents/Lew/PFinc
/media/WD_NAS_LEW/grsync/Documents/Lew/Trading
/media/WD_NAS_LEW/grsync/Documents/Lew/Trading
/media/WD_NAS_LEW/grsync/Documents/Lew/Trading/Studies & Lessons
/media/WD_NAS_LEW/grsync/Documents/Lew/Trading/Studies & Lessons
/media/WD_NAS_LEW/grsync/Documents/Lew/Trading
/media/WD_NAS_LEW/grsync/Documents/Lew/Trading/DVL/thinkscript
/media/WD_NAS_LEW/grsync/Documents/Lew/General/Essays & Letters
/media/WD_NAS_LEW/grsync/Documents/Lew/General/Long Fist et al Asia
/media/WD_NAS_LEW/grsync/Documents/Lew/General/Technology/Backup Procedures
/media/WD_NAS_LEW/grsync/Documents/Kids/Carey
/media/WD_NAS_LEW/grsync/Documents/Kids/Renee
/media/WD_NAS_LEW/grsync/Documents/Kids/Renee/Noah

It seems to be changing the field delimiter. Do I need to take out spaces in dir names, or there a way to leave them?

muru
  • 197,895
  • 55
  • 485
  • 740
Lew
  • 469
  • 1
  • 3
  • 17
  • 1
    I strongly suggest using rsync for backup – qwr Aug 26 '18 at 02:10
  • My understanding is that grsync is a gui wrapper around rsync. It worked for a while but doesn't any more. So I thought I'd try the manual route. – Lew Aug 26 '18 at 02:19
  • 5
    I've never used grsync but rsync has worked flawlessly for me. – WinEunuuchs2Unix Aug 26 '18 at 02:26
  • @WinEunuuchs2Unix the exclude rules and relative path are confusing for me but otherwise it works great (and has a progress bar) – qwr Aug 26 '18 at 02:30
  • 2
    @qwr I have a script that excludes virtual file systems / system temporary directories here: https://askubuntu.com/questions/1028604/bash-script-to-clone-ubuntu-to-new-partition-for-testing-18-04-lts-upgrade/1028605#1028605 – WinEunuuchs2Unix Aug 26 '18 at 02:32
  • @WinEunuuchs2Unix, grsync worked flawlessly and I liked it a lot. For a while. Then one day I spot checked some destination files, they hadn't been updated, and were not updated ever since. No error messages then in grsync or now when I drag N drop between Nautilus windows. Now I'm wondering if there's a problem with the connection to the NAS, but I don't know how to troubleshoot it. – Lew Aug 26 '18 at 22:50
  • You posted a question when you were burnt on March 29 by grsync. You haven't had much luck with it huh?: https://askubuntu.com/questions/1020393/arrgh-grsync-not-working-again – WinEunuuchs2Unix Aug 26 '18 at 22:54
  • Right. I'd like to be responsible and do incremental backups daily. I really want to be backed up before I leave on a trip. Grsync was making both of those easy, but when it stopped working I just gave up and have been doing it manually (but not regularly -- personal laptop, not corporate, but still...). Looking at a trip soon and decided to see if I could resolve it again. – Lew Aug 26 '18 at 22:59

1 Answers1

1

If you have a filename with a space in it, most commands interpret it as two file names. For example, if you have a file called "my file" and you attempt to copy it to /tmp as follows:

cp my file /tmp

the cp command will look for two files (Called my and file -- if they dont exist it will fail).

To overcome this, put quotes round the file name:

cp "my file" /tmp

you need to do the same in your script

cp -ru "$line" "$destname"

(bash will still expand variable names inside double quotes, but not single quotes)

I haven't filly checked your script -- there may be other places where you need to quote variable names.

btw -- there are lots of comments about using rsync. Once you get used to it its a much nicer way of backing up!

Nick Sillito
  • 1,596