logo NodeSeekbeta

一种通过dd便捷地全盘备份kvm机器的方法

12
  • @minlearn #9 发布于3/18/2023, 4:10:23 AM,编辑于3/18/2023, 6:27:32 AM

    | gzip -1 - " > backup.gz
    

    这是d到内存保存为文件么?这只有独服大内存或双盘能行,vps撑不下

    nc就不用保存文件

    minlearn这里对linux基础的管道实现没有理解到位,这是把dd的文件通过管道传输给gzip,然后把整体ssh命令的输出重定向到本地文件。过程是流式的,不需要把硬盘镜像完整加载到内存。可以参考:

    How do pipelines limit memory usage?

    The data doesn’t need to be stored in RAM. Pipes block their writers if the readers aren’t there or can’t keep up; under Linux (and most other implementations, I imagine) there’s some buffering but that’s not required. As mentioned by mtraceur and JdeBP (see the latter’s answer), early versions of Unix buffered pipes to disk, and this is how they helped limit memory usage: a processing pipeline could be split up into small programs, each of which would process some data, within the limits of the disk buffers. Small programs take less memory, and the use of pipes meant that processing could be serialised: the first program would run, fill its output buffer, be suspended, then the second program would be scheduled, process the buffer, etc. Modern systems are orders of magnitude larger than the early Unix systems, and can run many pipes in parallel; but for huge amounts of data you’d still see a similar effect (and variants of this kind of technique are used for “big data” processing).

    from stackexchange

    实际在230MB内存的机器测试了一下,仅占用了32MB内存(远程服务器A),本地的占用也很小,不存在整个dd到内存之说。

    利用nc进行文件传输也是一种方案,但这在我来看并不是上策,原因如下:

    • nc的监听段需要监听某个端口,把数据流重定向,这里没有授权检测,明文传输,ssh是包裹了一层tls的
    • nc一般要求在传输端和接收端都运行命令,ssh作为传输一般可以只在本地运行一条命令同时让远程完成dd和压缩的命令,更加凝练
    • nc有的时候并不随系统安装,但是ssh和dd一般都是作为基础工具安装的,不需要额外安装

    另外,我对你说的nc不用保存文件感到困惑,既然是异地备份,随时可以恢复的,那么本地不保存文件怎么可以留待以后恢复呢,你可以贴一下你用的命令吗

  • 大佬牛逼,mark并学习了!

  • @-X- #11
    nc明文可能快一点,但没有ssh安全吧

  • 谢谢分享

  • @zxxx #13

    嗯,明文传输会更快,cpu占用也更低

  • 🚫
  • @minlearn #16
    是,这个帖子要实现的目的是备份,为了方便测试,并不是为了安装系统

  • 谢谢分享

  • 支持一下。

12

你好啊,陌生人!

我的朋友,看起来你是新来的,如果想参与到讨论中,点击下面的按钮!

📈用户数目📈

目前论坛共有14645位seeker

🎉欢迎新用户🎉