Shell Script : Copy files from local folder to a Samba/NFS share

Posted By Sagar Patil

#!/bin/bash
source=”/backup”
remotePath=”/globalbackup/current”
archivePath=”/globalbackup/archive”
log=/home/oracle/scripts/cp_to_share.log
err=/home/oracle/scripts/cp_to_share.err

# I am going to rename files with timestamp so old shell files are preserved for future reference
timestamp=`date +%Y-%m-%d-%H%M`

#Move the shell file cp_to_share.sh
mv -f /home/oracle/scripts/cp_to_share.sh /home/oracle/scripts/cp_to_share.sh$timestamp
mv $log $log$timestamp
mv $err $err$timestamp

echo “### Let’s Move files copied y’day from remotePath to archivePath” >> /home/oracle/scripts/cp_to_share.sh

# Let’s Move files copied y’day from remotePath to archivePath
list=`find $remotePath -mtime -1 -type f`

for i in $list
do
echo “mv -f $i $archivePath” >> /home/oracle/scripts/cp_to_share.sh
done

echo “” >> /home/oracle/scripts/cp_to_share.sh
echo “” >> /home/oracle/scripts/cp_to_share.sh

echo “### Let’s start copying files at the global share” >> /home/oracle/scripts/cp_to_share.sh

# Copy files at the global share
list=`find /backup/ablxpora01/rman -mtime -1 -type f`
timestamp=`date +%Y-%m-%d-%H%M`

for i in $list
do
echo “cp $i $remotePath” >> /home/oracle/scripts/cp_to_share.sh
done
chmod +x /home/oracle/scripts/cp_to_share.sh
sh /home/oracle/scripts/cp_to_share.sh 1>>${log} 2>>${err}

Leave a Reply

You must be logged in to post a comment.

Top of Page

Top menu