I have an Ubuntu 16.04.2 DigitalOcean VPS to which I usually SSH with Putty and make changes in there, but I recently found out I can make a duplicate of this server in my PC (Win10 home with WSL), do the changes here locally, and then mirror them (while SSH tunneled) via a program called rsync
, if everything went good. The main benefit here is a comfortable, primary layer of backup.
If it is possible to use rsync in the WSL beta, how is it done from the moment rsync
is installed, for example, if I raise up a server environment at my Win10 home WSL with this code:
apt-get update -y && apt-get upgrade -y
apt-get install tree zip unzip make php-zip php-curl php-xml php-gd
apt-get install fail2ban
apt-get install lamp-server^ -y
a2enmod rewrite
sed -i 's/post_max_size \= .M/post_max_size \= 200M/g' /etc/php/7.0/apache2/php.ini # regex dot instead of 2 or 8.
sed -i 's/upload_max_filesize \= .M/upload_max_filesize \= 200M/g' /etc/php/7.0/apache2/php.ini
cat <<-'LAMPENV' >> /etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
LAMPENV
systemctl restart apache2.service
and I then bring up the websites on my PC locally with localhost/site_name
, how do I mirror it with rsync
to the VPS?
I ask this question mainly to see if what I described so far is enough – if I don't miss anything.
In an answer, please review the way I described above as a basis for the rsync
action and say if something missing, and detail how you would do so with rsync
in WSL afterwards.
Best Answer
First make sure you are able to connect over SSH from the remote machine to the local one. For this purpose you must copy your private key in the directory
/root/.ssh
and it has enough restrictions -sudo chmod 400 /root/.ssh/id_rsa
. Also you can create/root/.ssh/config
file as this:Now you can use
rsync
from the remote machine in this way:In case you don't have
/root/.ssh/config
file the command should be:Where:
-a
,--archive
is a quick way of saying you want recursion and want to preserve almost everything (with -H being a notable omission). The only exception to the above equivalence is when --files-from is specified, in which case -r is not implied.-v
,--verbose
increases the amount of information you are given during the transfer. By default, rsync works silently.-z
,--compress
- compress file data during the transfer.-p
,--perms
causes the receiving rsync to set the destination permissions to be the same as the source permissions. (See also the --chmod option for a way to modify what rsync considers to be the source permissions.)-e
,--rsh=COMMAND
allows you to choose an alternative remote shell program to use for communication between the local and remote copies of rsync...Also you can add here additional options to the
ssh
command. The options used in the above example-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
are useful to keep Rsync quiet and not prompting everytime you connect to a new server.--progress
show progress during transfer.Sources:
man rsync