Writing to two locations at once

I have a backup script that runs on CRON that I developed about 5 years ago. It has always worked perfectly but a recent firmware update on my QNAP TS 259 has seem to break the large file move/copy capability amongst the ESATA drives.

I would like to just change my backhup.sh so that writes to two locations at once, instead of writing to one location then using CP to copy it to another location.

 
 #!/bin/sh
 ####################################
 #
 # Backup to eSATA on NAS TS259.
 #
 ####################################
  
 # What to backup.
backup_files="/share/video/. /share/music/. /share/Web/. /share/tempdownload/. /share/Data/. /share/sheri.mccormack/. /share/pictures/. /share/Documents/. /share/charlie.mccormack/. /share/sydney.mccormack/. /share/persvideo/."
 
# Where to backup to.
 dest1="/share/eSATADisk1/"
dest2="/share/eSATADisk2/"
#dest3=""
#dest4=""
  
 # Create archive filename.
 day=$(date +%Y%m%d-%H%M%S)
hostname=$(hostname -s)
archive_file="$hostname-$day.tgz"
  
 # Print start status message.
 echo "Backing up $backup_files to $dest/$archive_file"
date
echo
  
 # Backup the files using tar.
 #tar czfP $backup_files | tee $dest1/$archive_file $dest2/$archive_file
 #tar czfP $dest2/$archive_file $backup_files
 cp -rfpv $dest2/* $dest1/
  
 # cp script for moving stuff around
 #cp -rfpv $dest3/*.* $dest4/
  
 # Print end status message.
 echo
 echo "Backup finished"
 date

 

I also use this file to just move stuff around by adding and removing the # signs. So above were I do the tar command I assume I could write to two locations at the same time. Just not sure how to do it.

Any help greatly appreciated.

In principle, sth. like

tar cz file* | tee XX.tgz > YY.tgz

seems to be doable, but never having done this I can't say if and where it will run into trouble.

1 Like

Thanks I will give this a shot and report back with results, for the benefit of the community.

---------- Post updated at 11:02 AM ---------- Previous update was at 10:17 AM ----------

I tried the following but didn't work

tar czfP $backup_files | tee $dest1/$archive_file > $dest2/$archive_file

Didn't work in which way?

How abou treading man tar ? I didn't put the f option into tar command.