dirA="/NAS/data/dir1/"; dirB="/mnt/databackup/dir1/"; while read(1posix) -r file; do relative="${file##"$dirA"}"; newfile="$dirB$relative"; mkdir(1) -p "$(dirname "$file")"; cp(1) -at "$file" "$newfile"; done < <(find "$dirA" -type f -mtime -1)
A variable may be assigned to by a statement of the form


If value is not given, the variable is assigned the null string.  All  values  undergo  tilde  expansion,
parameter  and  variable  expansion,  command  substitution, arithmetic expansion, and quote removal (see
EXPANSION below).  If the variable has  its  integer  attribute  set,  then  value  is  evaluated  as  an
arithmetic  expression even if the $((...)) expansion is not used (see Arithmetic Expansion below).  Word
splitting is not performed, with the exception of "$@"  as  explained  below  under  Special  Parameters.
Pathname  expansion  is  not performed.  Assignment statements may also appear as arguments to the alias,
declare, typeset, export, readonly, and local builtin commands.

In the context where an assignment statement is assigning a value to a shell variable or array index, the
+=  operator  can  be used to append to or add to the variable's previous value.  When += is applied to a
variable for which the integer attribute has been set, value is evaluated as an arithmetic expression and
added  to the variable's current value, which is also evaluated.  When += is applied to an array variable
using compound assignment (see Arrays below), the variable's value is not unset (as it is when using  =),
and  new  values  are  appended to the array beginning at one greater than the array's maximum index (for
indexed arrays) or added as additional key-value pairs in  an  associative  array.   When  applied  to  a
string-valued variable, value is expanded and appended to the variable's value.
Commands separated  by  a ; are executed sequentially; the shell waits for each command to terminate in turn.  The
return status is the exit status of the last command executed.
while list-1; do list-2; done
until list-1; do list-2; done
       The while command continuously executes the list list-2 as long as the last command  in  the  list
       list-1  returns  an  exit  status  of  zero.  The until command is identical to the while command,
       except that the test is negated; list-2 is executed as long as the last command in list-1  returns
       a non-zero exit status.  The exit status of the while and until commands is the exit status of the
       last command executed in list-2, or zero if none was executed.
read a line from standard input
-r     Do not treat a backslash character in any special way. Consider each backslash to be part  of  the
       input line.
make directories
-p, --parents
       no error if existing, make parent directories as needed
Create the DIRECTORY(ies), if they do not already exist.
copy files and directories
-a, --archive
       same as -dR --preserve=all
-t, --target-directory=DIRECTORY
       copy all SOURCE arguments into DIRECTORY
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
Before a command is executed, its input and output may be redirected using a special notation interpreted
by  the  shell.   Redirection  may  also  be used to open and close files for the current shell execution
environment.  The following redirection operators may precede or appear anywhere within a simple  command
or may follow a command.  Redirections are processed in the order they appear, from left to right.

Redirecting Input
    Redirection  of  input  causes  the  file  whose name results from the expansion of word to be opened for
    reading on file descriptor n, or the standard input (file descriptor 0) if n is not specified.

    The general format for redirecting input is:

source manpages: readmkdircp