원격 서버에 ext4 파일시스템 덤프파일 백업
클라우드 이미지 조작 및 덤프파일 복원
원본 (200G 디스크 / 21G 사용) → 원격 백업 → (40G 디스크에 복원)
백업
# OS 버전 확인 root@pdu-gics:~# lsb_release -a Description: Ubuntu 16.04.4 LTS Codename: xenial # 네트워크 정보 확인 root@pdu-gics:~# ifconfig -a ens160 Link encap:Ethernet HWaddr 00:50:56:95:5a:4e inet addr:aaa.bbb.100.43 Bcast:150.183.100.127 Mask:255.255.255.128 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 root@pdu-gics:~# cat /etc/network/interfaces auto lo iface lo inet loopback auto ens160 iface ens160 inet static address aaa.bbb.100.43 netmask 255.255.255.128 network aaa.bbb.100.0 gateway aaa.bbb.100.1 dns-nameservers aaa.bbb.95.96 # 중요 프로세스 확인 root@pdu-gics:~# ps auxf USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 119940 4884 ? S 2023 0:31 /sbin/init 6 ... mysql 1114 11.1 7.7 2636568 313480 ? Ssl 2023 13752:07 /usr/sbin/mysqld redis 1119 0.2 0.0 38856 2996 ? Ssl 2023 301:04 /usr/bin/redis-server *:6379 root 1260 1.6 0.8 612440 32880 ? Ssl 2023 2036:45 PM2 v4.2.0: God Daemon (/home/gdhong/.pm2) root 1273 0.1 1.8 922552 74428 ? Ssl 2023 223:34 \_ node /home/gdhong/.pm2/modules/pm2-logrotate/node_modules root 1706 0.6 2.4 966228 96928 ? Ssl 2023 766:27 \_ node /home/gdhong/Goodus/GICS-V4/bin/www root 1722 0.1 0.6 621084 26248 ? Ssl 2023 203:32 \_ node /home/gdhong/Goodus/GICS-V4/bin/proxy root 1723 0.1 0.6 618284 25764 ? Ssl 2023 208:35 \_ node /home/gdhong/Goodus/GICS-V4/bin/syslog root 5349 6.2 11.9 1025580 479560 ? Ssl 00:45 4:07 \_ node /home/gdhong/Goodus/GICS-V4/bin/collector # 파티션 확인 root@pdu-gics:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 200G 0 disk ├─sda1 8:1 0 487M 0 part /boot ├─sda2 8:2 0 1K 0 part └─sda5 8:5 0 199.5G 0 part ├─ubuntu--vg-root 252:0 0 198.5G 0 lvm / └─ubuntu--vg-swap_1 252:1 0 976M 0 lvm [SWAP] root@pdu-gics:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/ubuntu--vg-root 196G 21G 165G 12% / /dev/sda1 472M 58M 390M 13% /boot root@pdu-gics:~# cat /etc/fstab ... # <file system> <mount point> <type> <options> <dump> <pass> UUID=40fa19bd-42ef-4fac-908d-936f5738ebd3 /boot ext2 defaults 0 2 /dev/mapper/ubuntu--vg-root / ext4 errors=remount-ro 0 1 /dev/mapper/ubuntu--vg-swap_1 none swap sw 0 0 # 원격서버(remote)에 ext4 파일시스템 덤프 # dd 명령과는 다르게 사용중인 용량만 덤프됨 root@pdu-gics:# dump -0u -f - /dev/ubuntu-vg/root | ssh -p 2204 root@remote dd of=/root/pdu-gics-root.dump DUMP: Date of this level 0 dump: Wed Jan 10 00:53:53 2024 DUMP: Dumping /dev/ubuntu-vg/root (an unlisted file system) to standard output root@remote-backup-server's password: **** DUMP: Label: none DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 21753915 blocks. DUMP: Volume 1 started with block 1 at: Wed Jan 10 00:53:58 2024 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: 15.81% done at 11463 kB/s, finished in 0:26 DUMP: 33.28% done at 12066 kB/s, finished in 0:20 DUMP: 45.71% done at 11048 kB/s, finished in 0:17 DUMP: 56.18% done at 10184 kB/s, finished in 0:15 DUMP: 71.25% done at 10333 kB/s, finished in 0:10 DUMP: 84.99% done at 10271 kB/s, finished in 0:05 DUMP: Volume 1 completed at: Wed Jan 10 01:28:16 2024 DUMP: Volume 1 21740730 blocks (21231.18MB) DUMP: Volume 1 took 0:34:18 DUMP: Volume 1 transfer rate: 10564 kB/s DUMP: 21740730 blocks (21231.18MB) DUMP: finished in 2058 seconds, throughput 10564 kBytes/sec DUMP: Date of this level 0 dump: Wed Jan 10 00:53:53 2024 DUMP: Date this dump completed: Wed Jan 10 01:28:16 2024 DUMP: Average transfer rate: 10564 kB/s DUMP: DUMP IS DONE 43481460+0 records in 43481460+0 records out 22262507520 bytes (22 GB, 21 GiB) copied, 2059.25 s, 10.8 MB/s
복원
# 비슷한 버전의 클라우드 이미지 찾아 다운로드 root@remote:~# wget https://cloud-images.ubuntu.com/xenial/20211001/xenial-server-cloudimg-amd64-disk1.img 2024-01-10 07:22:17 (9.14 MB/s) - ‘xenial-server-cloudimg-amd64-disk1.img’ saved [315359232/315359232] # 클라우드 이미지 확인 root@remote:~# IMG=xenial-server-cloudimg-amd64-disk1.img root@remote:~# virt-filesystems -l -h --all -a $IMG Name Type VFS Label MBR Size Parent /dev/sda1 filesystem ext4 cloudimg-rootfs - 2.2G - /dev/sda1 partition - - 83 2.2G /dev/sda /dev/sda device - - - 2.2G - # 클라우드 이미지 복사 및 조작 root@remote:~# NEW=pdu-gics.qcow2 root@remote:~# cp $IMG $NEW root@remote:~# qemu-img resize $NEW 40G Image resized. root@remote:~# qemu-nbd --connect=/dev/nbd0 $NEW root@remote:~# lsblk /dev/nbd0 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nbd0 43:0 0 40G 0 disk └─nbd0p1 43:1 0 2G 0 part root@remote:~# growpart /dev/nbd0 1 CHANGED: partition=1 start=2048 old: size=4608000 end=4610048 new: size=83883999 end=83886047 root@remote:~# e2fsck -f /dev/nbd0p1 e2fsck 1.45.5 (07-Jan-2020) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information cloudimg-rootfs: 60903/288000 files (0.0% non-contiguous), 265054/576000 blocks root@remote:~# resize2fs /dev/nbd0p1 resize2fs 1.45.5 (07-Jan-2020) Resizing the filesystem on /dev/nbd0p1 to 10485499 (4k) blocks. The filesystem on /dev/nbd0p1 is now 10485499 (4k) blocks long. root@remote:~# lsblk /dev/nbd0 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT nbd0 43:0 0 40G 0 disk └─nbd0p1 43:1 0 40G 0 part # 클라우드 이미지의 부팅 관련 파일 백업 root@remote:~# mkdir -p bak/etc root@remote:~# cp -arp /mnt/linux/boot /root/bak root@remote:~# cp -arp /mnt/linux/etc/default/ /root/bak/etc root@remote:~# cp -arp /mnt/linux/etc/grub.d /root/bak/etc root@remote:~# cp -arp /mnt/linux/etc/fstab /root/bak/etc # 클라우드 이미지에 ext4 덤프파일 복원 root@remote:~# cd /mnt/linux root@remote:/mnt/linux# rm -rf * root@remote:/mnt/linux# time restore -rf /var/lib/libvirt/images/pdumgr-root.dump restore -rf /var/lib/libvirt/images/pdumgr-root.dump 2.66s user 28.43s system 4% cpu 12:51.50 total # 복원된 파일 중 변경해야 할 파일 백업 root@remote:/mnt/linux# mv boot boot.old root@remote:/mnt/linux# mv etc/default etc/default.old root@remote:/mnt/linux# mv etc/grub.d etc/grub.d.old root@remote:/mnt/linux# mv etc/fstab etc/fstab.old # 부팅 관련 파일은 클라우드 이미지의 파일을 사용하도록 설정 root@remote:/mnt/linux# mv /root/bak/boot . root@remote:/mnt/linux# mv /root/bak/etc/default etc root@remote:/mnt/linux# mv /root/bak/etc/grub.d etc root@remote:/mnt/linux# mv /root/bak/etc/fstab etc root@remote:/mnt/linux# cd ~ root@remote:~# sync root@remote:~# umount linux root@remote:~# qemu-nbd --disconnect /dev/nbd0 root@remote:~# ls -alh 21G pdu-gics-root.dump 24G pdu-gics.qcow2