Skip to content

Instantly share code, notes, and snippets.

@theand
Last active December 11, 2015 07:09
Show Gist options
  • Save theand/4564532 to your computer and use it in GitHub Desktop.
Save theand/4564532 to your computer and use it in GitHub Desktop.
#BASH execute remote script, fetch archive, delete old archive
#!/bin/bash
eval `ssh-agent`
keychain id_dsa
. /root/.keychain/localhost-sh
remote_dir="/backup/home_backup/latest_home_backup"
local_dir="/backup/home_backup"
dir_name="$(date +%Y%m%d)"
/usr/bin/ssh root@remote.server "/root/home_backup.sh"
mkdir $local_dir/home.$dir_name
/usr/bin/scp root@remote.server:$remote_dir/* $local_dir/home.$dir_name
let "i = 0"
for dname in $(ls -t $local_dir)
do
let " i = i + 1"
if [ $i -ge "10" ]; then
if [ -d $local_dir/$dname ]; then
echo "Deleting old archive - $dname"
rm -rf $local_dir/$dname
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment