Skip to content

Instantly share code, notes, and snippets.

@theand
Created January 18, 2013 13:34
Show Gist options
  • Save theand/4564556 to your computer and use it in GitHub Desktop.
Save theand/4564556 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/mysql_sql_backup"
local_dir="/backup/mysql_sql_backup"
/usr/bin/ssh root@remote.server "/root/mysql_sql_back.sh"
/usr/bin/scp root@remote.server:$remote_dir/latest_sql_backup.tar.gz "$local_dir/mysql_sql.$(date +%Y%m%d).tar.gz"
let "i = 0"
for fname in $(ls -t $local_dir)
do
let "i = i + 1"
if [ $i -ge "80" ]; then
if [ -f $local_dir/$fname ]; then
echo "Deleting - $fname"
rm -f $local_dir/$fname
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment