Skip to content

Instantly share code, notes, and snippets.

@nk952777
Last active May 27, 2021 05:02
Show Gist options
  • Save nk952777/d203bf09ff08f1525b6af1b5c71efad2 to your computer and use it in GitHub Desktop.
Save nk952777/d203bf09ff08f1525b6af1b5c71efad2 to your computer and use it in GitHub Desktop.
backup2gdrive
#!/bin/bash
source /root/.bash_profile
today=$(date +"%Y-%m-%d")
DIR=/root/backup2gdrive/www.wcpweb.xyz/${today}
if [ ! -d "$DIR" ]; then
mkdir -p /root/backup2gdrive/www.wcpweb.xyz/${today}
fi
cd /root/backup2gdrive/www.wcpweb.xyz/${today}
tar zcf wcpweb_web_${today}_"`date +%s`".tar.gz /home/wwwroot/www.wcpweb.xyz
mysqldump -u user -pHEREISYOURPW mydb > mydb_db_${today}_"`date +%s`".sql
yes | drive push /root/backup2gdrive/www.wcpweb.xyz/${today}
cd /root/backup2gdrive/www.wcpweb.xyz
fn=`ls | wc -l`
if [ $fn -gt 3 ] ; then
dn=$[$fn-3]
dc=0
for output in `ls -rt`; do
if [ $dc -ge $dn ] ; then
break
fi
echo $output
Y | drive delete $output
rm -rf $output
((dc++))
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment