Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goxofy/115d31e51d06e7483e156dd17d2cdf6d to your computer and use it in GitHub Desktop.
Save goxofy/115d31e51d06e7483e156dd17d2cdf6d to your computer and use it in GitHub Desktop.
Backup Archlinux and Restore to another machine
## Backup the current vps 备份当前vps
1. Clean Arch system 清理系统
pacman -Scc
2. Create an excluded file to exclude certain dirs 建立一个需要排除的目录的文件,这些文件不必要备份,新系统会自动生成
cat /root/backup/exclude.txt
/tmp/*
/root/backup/*
/proc
/dev
/sys
3. Backup with tar 用tar备份当前系统
tar --exclude-from=/root/backup/exclude.txt -czpvf /root/backup/archlinux-backup.tar.gz /
## Restore to new vps 还原到新的服务器
1. Boot to the new VPS from archlinux CDROM from VPS provider's Console 通过vps的管理界面光盘启动
2. Partition the disk to the same structure with the source server which is the backup system 给新系统分区,保持与就系统同样的分区结构
cfdisk /dev/vda
3. format the root and mount to /mnt, also create a swap partition. 格式化根目录分区,并mount, 同时创建swap分区
mkfs.ext4 /dev/vda1
mount /vda1 /mnt
mkswap /dev/vda2
swapon /dev/vda2
4. scp archlinux-backup.tar.gz from old vps to /mnt 将先前备份的arch拷贝到 /mnt
scp username@server:/root/backup/archlinux-backup.tar.gz /mnt/
5 extract the backup file 解压到新服务器的根目录,也就是/mnt目录
cd /mnt
tar -xvf archlinux-backup.tar.gz
6 create missed dirs 创建之前忽略掉的文件夹
cd /mnt
mkdir proc sys dev
7 generate the new fstab 生成新的fstab
genfstab -U -p /mnt > /mnt/etc/fstab
8 chroot to the new root chroot到新的系统
arch-chroot /mnt /bin/bash
9 reinstall grub and grub.cfg 安装grub到新系统并生成配置文件
grub-install --target=i386-pc --recheck /dev/vda
grub-mkconfig -o /boot/grub/grub.cfg
## Remarks
1 Finished, reboot, note the new machine has a new ip address, do not forget to apply the new ip to the files that has specified an ip address. 至此完成,新系统会有新的ip地址,如果之前的系统某些文件特别定义了ip地址,需要做相应的修改。
2 If you have custome build, you have to makepkg again on the new system, because the CPU is different. 如果之前有自定义安装的包,需要再新系统里面重新makepkg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment