Created
July 13, 2018 00:14
-
-
Save simbalinux/8a7676e2ac85fa47a31857765f483b7a to your computer and use it in GitHub Desktop.
backup_script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#set -x | |
shopt -s nullglob | |
data=(/nas/csi/*) | |
key="$HOME"/.ssh/csi | |
[email protected]:/Drop | |
archive=/nas/data/.data_archive | |
now=$(date +"%Y%m%d-%T") | |
sftp_copy () { | |
(( ${#data[@]} )) || { echo "No File in /nas/data/. Nothing for SysAdmin to do. Contact DBA for files." >& 2; exit 1; } | |
for item in "${data[@]}"; do | |
sftp -oConnectTimeout=10 -oIdentityFile="$key" "$url" <<EOF | |
put "$item" | |
ls | |
quit | |
EOF | |
[ $? = 0 ] || exit 1 | |
done | |
} | |
data_archive () { | |
for each in "${data[@]}"; do | |
mv "$each" "$archive"/"${each##*/}"_"$now" | |
done | |
} | |
echo "Checking for files ..." | |
sftp_copy | |
data_archive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment