0

I need a simple bash script to copy some directories from my HD to a external USB support. For both SOURCE and TARGET are difefrent, I solved with an not elegant code:

#!/bin/bash
USER=`whoami`
SOURCE=( /mnt/archive/articles /mnt/archive/bibliographies /mnt/archive/catalogues )
TARGET="/media/$USER/Elements/samiel"
date=`date "+%y-%M-%D"`
# Tag of log in /var/log/messages
TAG="backup_samiel"
rsync -avzu --delete --delete-after --progress ${SOURCE[@]} $TARGET

#######################################################################

SOURCE=( /mnt/archive/Music )
TARGET="/media/$USER/Elements/"
date=`date "+%y-%M-%D"`
# Tag of log in /var/log/messages
TAG="backup_Music"
rsync -avzu --delete --delete-after --progress ${SOURCE[@]} $TARGET

But maybe there is a more elegant way to do it! I tried something as

#!/bin/bash
USER=`whoami`
declare -A BACKUP_INFOS
BACKUP_INFOS=(
    [/media/samiel/Elements/samiel]="/mnt/archive/articles
/mnt/archive/bibliographies /mnt/archive/catalogues"
    [/media/samiel/Elements/Music]="/mnt/archive/Music"
)
for dest_dir in "${!BACKUP_INFOS[@]}"
do
  mkdir -p "$dest_dir"
  src="${BACKUP_INFOS[$dest_dir]}"
  rsync -rvuz --delete --delete-after --progress $src "$dest_dir"
done

but I receive a list of errors

samiel@darkstar:~/system_files$ bash elements.sh 
building file list ... 
1 file to consider
The Romantic Violin Concerto Hyperion Vol. 1 to 12.iso
  2,188,584,960 100%   80.59MB/s    0:00:25 (xfr#1, to-chk=0/1)
sent 2,133,273,798 bytes  received 34 bytes  80,500,899.32 bytes/sec
total size is 2,188,584,960  speedup is 1.03
building file list ... 
55 files to consider
skipping non-regular file "articles"
skipping non-regular file "bibliographies"
skipping non-regular file "catalogues"
.
.
.
rsync error: some files/attrs were not transferred (see previous  errors) (code 23) at main.c(1330) [sender=3.2.3]

What is wrong in this last code? Thank you! s

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.