Reinstall Server From Recovery Disk with RSYNC

Few weeks ago, my Amsterdam instance out of space. My all projects is in my workstation (also Github and Gitlab) and I make a sync with mirrorfy to server. I can purge or re install my server without losing (because everything has a backup) any data but I try to truncate log files to gain a bit space in server. I made a huge mistake while emptying log files 😁. Normally I have to write truncate command with */* arg while in /var/log folder to truncate files but lack of sleep cause to write a /*/* and most of the binaries and some important system files is gone 😂.

So again I turn back to my first idea which is re install my server.

I suggest that take a backup of your system before taking a action.
You can take a backup with dibow, filezilla or others.
After getting a backup, check your backup to prevent loss any data. Some times data can be corrupt while transferring data.

How to reinstall server with rsync ?

Switch to rescue mode

Firstly you have to reboot your server in rescue mode.
Most of the cloud providers has a rescue mode feature. You can easily switch server mode to rescue mode.
I have point that Your rescue mode is your new OS in normal mode, because ve are copy rescue mode System files to your server disk.

Determine the disk

List your disks with df command to determine which disk is your server partition.

user@example-server:~# df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            448M     0  448M   0% /dev
tmpfs            99M  1.1M   98M   2% /run
/dev/vda2       9.8G  4.8G  4.6G  52% /
tmpfs           491M     0  491M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           491M     0  491M   0% /sys/fs/cgroup
tmpfs            99M     0   99M   0% /run/user/0

For this example server, instance has a 10G disk and we can detect the disk device which is see as a same info with the output of the program.

I can easy say /dev/vda2 is my main server disk.

Format the server disk

We have to delete all old files in server. We can also overwrite the system files but this is not recommend, because some databases is refreshed but applications is already in your disk, such as docker is installed to server but aptitide does not know that and while updating it creates a conflict.

Note: This operation delete all data in your disk. Please be sure you don’t have a important data and your are selecting a right disk.

user@example-server:~# mkfs.ext4 /dev/vda2 # Do not forget to change with your volume

Mount the server volume

Your server disk is empty. To reach newly formatted volume ve can mount disk to server before copying data.

user@example-server:~# mkdir /mnt
user@example-server:~# mount /dev/vda2 /mnt # Do not forget to change with your volume

Copy rescue mode OS to Server

Now ve can copy the Rescue mode disk into to server’s volume

user@example-server:~# rsync -ahPHAXx --exclude={/dev/,/proc/,/sys/,/tmp/,/run/,/mnt/,/media/*,/lost+found} / /mnt

Last part

Set your server to normal boot mode and reboot. Check your server is already updated. For example some cloud provider’s rescue disk is old and needs to be updated to patch security vulnerabilities.


© 2024 All rights reserved.

Powered by Hydejack v7.5.0