Skip to content

Instantly share code, notes, and snippets.

@binux
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save binux/1cc3d2df8c4be1aac340 to your computer and use it in GitHub Desktop.
Save binux/1cc3d2df8c4be1aac340 to your computer and use it in GitHub Desktop.
#!/bin/bash
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# Author: Binux<i@binux.me>
# http://binux.me
# Created on 2014-10-23 23:26:46
PROCESSOR=`uname -p`
# make tools dir
mkdir -p $HOME/tools
cd $HOME/tools
# get tools
# btsync
if [ $PROCESSOR == "x86_64" ]; then
curl http://download-new.utorrent.com/endpoint/btsync/os/linux-glibc23-x64/track/stable | tar xzvf -
else
curl http://download-new.utorrent.com/endpoint/btsync/os/linux-glibc23-i386/track/stable | tar xzvf -
fi
if [ ! -e btsync ]; then
echo "download btsync error"
exit 1
fi
# daemon.sh
if [ ! -e daemon.sh ]; then
curl -L https://gist.github.com/binux/1587684/raw/daemon.sh > daemon.sh
chmod +x daemon.sh
fi
# init btsync
W_SECRET=`$HOME/tools/btsync --generate-secret`
R_SECRET=`$HOME/tools/btsync --get-ro-secret $W_SECRET`
cat > btsync.conf <<- EOF
{
"device_name": "`hostname`",
"listening_port" : 0, // 0 - randomize port
// "pid_file" : "/var/run/btsync/btsync.pid",
"use_upnp" : false,
"download_limit" : 0,
"upload_limit" : 0,
"webui" : { } ,
"shared_folders" :
[
{
"secret" : "$W_SECRET", // required field - use --generate-secret in command line to create new secret
"dir" : "$HOME/backup", // * required field
"use_relay_server" : true, // use relay server when direct connection fails
"use_tracker" : true,
"use_dht" : false,
"search_lan" : true,
"use_sync_trash" : true, // enable SyncArchive to store files deleted on remote devices
"overwrite_changes" : false, // restore modified files to original version, ONLY for Read-Only folders
"known_hosts" : [ ]
}
]
}
EOF
cat > btsync.sh <<- EOF
#!/bin/bash
init () {
echo "init"
cd `pwd`
}
run () {
echo "run"
./btsync --nodaemon --config btsync.conf
}
cleanup () {
:
}
source \$(dirname \$0)/daemon.sh
EOF
chmod +x btsync.sh
(crontab -l ; echo "* * * * * `pwd`/btsync.sh") | crontab -
mkdir -p $HOME/backup
cat > backup.sh <<- EOF
#!/bin/bash
cd $HOME/backup
echo "BACKUP START AT: \`date +%D-%H:%M:%S\`" > BACKUP_TIME
BACKUPS="/etc/nginx \\
/srv \\
$HOME"
rsync -av --delete \$BACKUPS --exclude=backup --exclude=_* ./
crontab -l > crontab
#mysqldump -u'user' -p'passowd' --lock-tables=FALSE table > table.sql
echo "BACKUP END AT: \`date +%D-%H:%M:%S\`" >> BACKUP_TIME
EOF
chmod +x backup.sh
(crontab -l ; echo "0 * * * * `pwd`/backup.sh") | crontab -
echo "read only secret: $R_SECRET"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment