Showing posts with label remote. Show all posts
Showing posts with label remote. Show all posts

Monday, September 11, 2017

Ubuntu auto backup to remote host using scp rsync crontab

Ubuntu auto backup to remote host using scp rsync crontab


Bash script to transfer files via SCP

#!/bin/bash 
REMOTE_IP="x.x.x.x"
SCP_PASSWORD="mypassword"
expect -c "
set timeout 1
spawn scp -r /Local/SourceFolder uname@$REMOTE_IP:/Remote/DestFolder
expect yes/no { send yes ; exp_continue }
expect password: { send $SCP_PASSWORD }
expect 100%
sleep 1
exit
"
Save the above script to autoscp.sh and give the execute permission. The SourceFolder is the folder whose contents are sent to DestFolder on the remote host .
$ chmod +x file.sh
$ ./file.sh
Install expect if its not on our machine, expect  is a program that "talks" to other interactive programs according to a script. We use this in this script to provide the password when asked for by the scp command.
sudo apt-get install expect

Bash script to sync local & remote folder via rsync

#!/bin/bash 
REMOTE_IP="x.x.x.x"
SCP_PASSWORD="mypassword"
#And now transfer the file over
expect -c "
set timeout 1
spawn rsync -azvv -e ssh /Local/SrcFolder uname@$REMOTE_IP:/Remote/DstFolder
expect yes/no { send yes ; exp_continue }
expect password: { send $SCP_PASSWORD }
expect 100%
sleep 1
exit
"
-a preserves the date and times, and permissions of the files
-z compresses the data
-vv increases the verbosity of the reporting process
-e specifies remote shell to use

Save the above script to autorsync.sh file and give the execute permission.
Refer this Ubuntu documentation for more details on rsync. Both the bash scripts mainly automate the rsync and scp transfer, so that password dont need to be supplied.

Scheduling this rsync and scp scripts to run periodically

Use crontab to schedule these scripts to run periodically. To edit crontab use
crontab -e
Add the below lines
# m h dom mon dow command
0 * * * * cd /location/of/script;./autoscp.sh
30 * * * * cd /location/of/script;./autorsync.sh
m - minute
h - hour
dom - day of the month
mon - month
dow - day of the week
0 * * * *  will run the script at 0 minutes every hour, every day of all the months.
30 * * * * will run the script at every 30 minutes on every hour, every day of all the months.

download file now

Read more »

Thursday, August 10, 2017

Tutorial Port Forwarding Mikrotik Untuk Remote Winbox

Tutorial Port Forwarding Mikrotik Untuk Remote Winbox




Beberapa menit yang lalu ada teman Bertanya, apakah bisa remote 3 RB Mikrotik. Antara lain
  1. Mikrotik-1 adalah Mikrotik Utama, di Pati
  2. Mikrotik-2 adalah untuk Hotspot atau Lan di Winong
  3. Mikrotik-3 adalah untuk Hotspot atau Lan di Kuryokalangan
Nah teman ini bertanya, pada saat saya keluar kota, apakah bisa saya me-remote 3 Mikrotik ini secara bersamaan dan sekaligus. Lalu saya jawab, Bisa Boss� (wakakakaka suka aja panggil dia Boss abis bener boss Hotspot sih). dan saya ajari si Boss ini cara settingnya dan saya buktikan dengan meremote RB Mikrotik-2 dan Mikrotik-3. Its running well�.
So.. bijimana eh bagaimana cara setting nya.. silakan tetap duduk manis, jangan kemana-mana setelah jeda komersial berikut ini�.. lanjut bozzz�..
Sebelum kita setting, kita pahami dulu beberapa hal sebagai berikut :
  • IP Public/Internet di Mikrotik-1 Utama,  saya umpamakan adalah 118.97.212.212
  • IP Ether1 di Mikrotik-2 saya umpamakan adalah 192.168.1.253
  • IP Ether1 di Mikrotik-3 saya umpamakan adalah 192.168.1.252
Perlu diketahui bahwa port default winbox di Mikrotik adalah 8291 oleh karena itu kita akan mengganti port winbox di Mikrotik-2 dan Mikrotik-3 sesuai dengan keinginan kita. Namun agar mempermudah mengingat kita ganti menjadi port 8292 dan 8293.
Terlebih dahulu anda remote Mk-2, masuk ke menu IP Services, nah akan terlihat service port untuk winbox 8291 anda dobel klik lalu ganti menjadi port 8292 klik apply OK.. Sampai disini anda TIDAK AKAN BISA meremote MK-2 lagi karena default port winbox sudah anda ganti sehingga jika anda meremote kembali MK-2 maka anda harus menambahkan port 8292 seperti ini di winbox anda. 192.168.1.253:8292. Sampai disini apakah anda sudah paham ?? jika ya, lanjut..
Nah berikutnya kita coba meremote MK-2 dari MK-1, namun kita harus mensetting di menu NAT terlebih dahulu. Anda remote MK-1, masuk menu IP Firewall NAT, klik tanda + lalu isikan sebagai berikut :
  • chain=dstnat
  • Dst.Address=118.97.212.212
  • Protocol=tcp
  • Dst.Port=8292
  • Action=dst-nat
  • To Addresses=192.168.1.253
  • To Ports=8292
Klik apply, OK. selesai.
Dari settingan ini anda sudah bisa meremote MK-2 yang notabene adalah ip local. Coba anda remote dari luar jaringan anda, atau dari jaringan MK-1 untuk meremote MK-2.  dengan cara buka winbox lalu isikan ip nya 118.97.212.212:8292   . Harusnya anda sudah bisa masuk ke MK-2.

download file now

Read more »