Using SCP in Linux
After securing your Linux VPS and deploying web server applications, it is time to synchronize web server files from old VPS to VPSie.
This article assumes that source and destination systems have the same users with the same user IDs – especially daemon application users.
There are new fashion methods (like puppet or git) and multiple old fashion and straight forward methods: using rsync (not installed by default in all Linux distributions), scp if you are copying from another Linux machine or WinSCP if you are copying from a Windows machine.
I will shortly discuss SCP command here. To synchronize a directory from local host to your remote new VPSie, one needs to use especially the “-r Recursively copy entire directories. Note that scp follows symbolic links encountered in the tree traversal.” option.
$ scp -r /tmp/test.origin myfirstvpsie:/tmp/test.destination/
user@myfirstvpsie$ ls -la /tmp/test.destination/
drwxr-xr-x 3 root root 4096 Nov 23 15:59 .
drwxrwxrwt 3 root root 4096 Nov 23 15:57 ..
drwxr-xr-x 2 root root 4096 Nov 23 15:59 test.origin
Scp also supports shell wildcard input for selective file names copy:
$ ls -la
drwxr-xr-x 2 root root 4096 Nov 23 22:56 .
drwxrwxrwt 6 root root 319488 Nov 23 23:21 ..
-rw-r–r– 1 root root 0 Nov 23 22:56 abcd
-rw-r–r– 1 root root 0 Nov 23 22:56 bcde
-rw-r–r– 1 root root 0 Nov 23 22:56 degh
-rw-r–r– 1 root root 0 Nov 23 22:56 eghi
Below, I will copy only files that contain the string “bc” in the middle.
$ scp /tmp/test.origin/*bc* 126.96.36.199:/tmp/test.destination
user@myfirstvpsie$ ls -la
drwxr-xr-x 2 root root 4096 Nov 23 16:22 .
drwxrwxrwt 3 root root 4096 Nov 23 16:17 ..
-rw-r–r– 1 root root 0 Nov 23 16:22 abcd
-rw-r–r– 1 root root 0 Nov 23 16:22 bcde
Few other scp options that need to be checked out are:
*** Mandatory *** User ownership, file timestamps and permissions:
-p Preserves modification times, access times, and modes from the original file.
Specifies the port to connect to on the remote host. Note that this option is written with a capital “Pâ”, because -p is already reserved for preserving the times and modes of the file
To confirm origin and destination directories are in sync, one can use find command to confirm same number of files:
$ find /tmp/test.origin -type f | wc -l
$ find /tmp/test.destination -type f | wc -l
Check destination directory on the destination server have the same permissions as origin one.
You can actually try those SCP steps on our platform in few minutes utilizing our PCS (Private Cloud Solution) which allows you to have VPSie(s) on a private network – NAT – Port forward – traffic control for inbound and outbound – multiple gateway IPs which you could use for the load-balancing and failover.