2

I would like to do backups of my /home partition of my computer with Linux (Lubuntu 20.04) on weekly basis. The catch is that the only extra hard drive I own is connected to Windows machine. It seems that Windows can not manage ext3 or ext4 partitions without some third-party tools (and I have no idea how reliable those are). It looks like I have no choice but to do backups on a NTFS volume.

So, here comes the question. How to do it properly?

I found a similar question on this thread, but it was asked and answered (I am talking about the second answer which is more concrete, than the accepted one) ten years ago. I copied the relevant part here for convenience.

To back up:

ionice -c2 -n5 nice -n9 tar czvf - /media/somelinuxdrivepath | split -b 16m - /media/usb/ntfsmounted/back.tar.gz. 

To restore from backed up copy:

ionice -c2 -n5 nice -n9 cat /media/usb/ntfsmounted/back.tar.gz.* | tar xzvf - /media/somenewlinuxpath 

I have three doubts about the answer, though, which are as follows:

  1. Ten years is quite a lot, so is there any chance something more reliable and/or convenient has appeared since than (some special tool designed for just this purpose)?
  2. I really do not understand the part that comes before the tar command, I have tried but this is beyond me.
  3. In my case the /home partition size is more than 200 GB. Is it rationale to back everything up every weekend, if I have changed just a handful of files during the week? Something like Rsync sounds like a logical choice, but will it be a complete copy that can be used to restore the partition completely?
2
  • 1
    Backing up this way is extremely ill-advised. No file versioning, no incremental backups, no backup formal verification, no recovery record, no check-summing, nothing. If a first file of your backup gets damaged, your entire backup is 100% worthless. Your issue is not NTFS, your issue is choosing the right tool for the job. Tar with XZ is not it. Commented Dec 27, 2023 at 7:16
  • nice and ionice are for assigning a CPU priority [0-19] and I/O priority [0-7] to a command, respectively. Lower numbers are higher priority in both cases. nice -n9 ionice -c 3 COMMAND puts it at nice level 9 (lower CPU priority) and I/O priority 3 (idle). ionice is NOT available on *BSD, and by extension it's not available in OSX. Commented Jan 11, 2024 at 18:26

2 Answers 2

2

you can use getfacl and setfacl to backup/restore the permissions / ownership of files when copying between ntfs and other filesystems on linux:

to backup:

cp -rv /home /mnt/ntfs_vol getfacl -R /home | xz -9 > /mnt/ntfs_vol/home_permissions.txt.xz 

to restore:

cp -rv /mnt/ntfs_vol/home / setfacl --restore <(xzcat /mnt/ntfs_vol/home_permissions.txt.xz) 

EDIT:

Someone mentioned in a comment earlier the different between formal and informal backups / verification, and you can substitute rsync for cp:

TS=$(date '+%Y%m%d%H%M%s') ; rsync -avv /home \ /mnt/ntfs_vol \ --log-file="/mnt/ntfs_vol/rsync.${TS}.log" && \ getfacl -R /home \ | xz -9 > "/mnt/ntfs_vol/home_permissions.${TS}.txt.xz" 

references:

https://superuser.com/questions/1002074/linux-command-line-to-create-a-log-file-for-rsync

Back up and restore file permissions

if you require more formal verification than that, then you could also produce a manifest of cryptographic hashes:

apt install parallel TZ=$(date '+%Y%m%d%H%M%s') ; find /home \ -type f | parallel sha256sum {} \ > "/mnt/ntfs_vol/backup.${TZ}.manifest" 

and to verify:

sha256sum --quiet -c /mnt/ntfs_vol/backup.2023122707571703692656.manifest 

If you don't like tar, because of the name, or whatever reason but can appreciate having an archival format there is another fairly common alternative:

find /home | cpio -vo > /mnt/ntfs_vol/archive.cpio 

and if you inspect the contents of this format:

find /usr/include/ | cpio -o | hexdump -C | head -n 20 00000000 c7 71 1d 00 9c 09 ed 41 00 00 00 00 01 00 00 00 |.q.....A........| 00000010 83 65 9c 05 0e 00 00 00 00 00 2f 75 73 72 2f 69 |.e......../usr/i| 00000020 6e 63 6c 75 64 65 2f 00 c7 71 1d 00 f9 47 ed 41 |nclude/..q...G.A| 00000030 00 00 00 00 01 00 00 00 92 64 2a 63 16 00 00 00 |.........d*c....| 00000040 00 00 2f 75 73 72 2f 69 6e 63 6c 75 64 65 2f 69 |../usr/include/i| 00000050 70 72 6f 75 74 65 32 00 c7 71 1d 00 f2 d6 a4 81 |proute2..q......| 00000060 00 00 00 00 01 00 00 00 6b 64 f8 6b 20 00 00 00 |........kd.k ...| 00000070 f7 04 2f 75 73 72 2f 69 6e 63 6c 75 64 65 2f 69 |../usr/include/i| 00000080 70 72 6f 75 74 65 32 2f 62 70 66 5f 65 6c 66 2e |proute2/bpf_elf.| 00000090 68 00 2f 2a 20 53 50 44 58 2d 4c 69 63 65 6e 73 |h./* SPDX-Licens| 000000a0 65 2d 49 64 65 6e 74 69 66 69 65 72 3a 20 47 50 |e-Identifier: GP| 000000b0 4c 2d 32 2e 30 20 2a 2f 0a 23 69 66 6e 64 65 66 |L-2.0 */.#ifndef| 000000c0 20 5f 5f 42 50 46 5f 45 4c 46 5f 5f 0a 23 64 65 | __BPF_ELF__.#de| 000000d0 66 69 6e 65 20 5f 5f 42 50 46 5f 45 4c 46 5f 5f |fine __BPF_ELF__| 000000e0 0a 0a 23 69 6e 63 6c 75 64 65 20 3c 61 73 6d 2f |..#include <asm/| 000000f0 74 79 70 65 73 2e 68 3e 0a 0a 2f 2a 20 4e 6f 74 |types.h>../* Not| 00000100 65 3a 0a 20 2a 0a 20 2a 20 42 65 6c 6f 77 20 45 |e:. *. * Below E| 00000110 4c 46 20 73 65 63 74 69 6f 6e 20 6e 61 6d 65 73 |LF section names| 00000120 20 61 6e 64 20 62 70 66 5f 65 6c 66 5f 6d 61 70 | and bpf_elf_map| 00000130 20 73 74 72 75 63 74 75 72 65 20 64 65 66 69 6e | structure defin| 

It's dead simple; having no programming experience whatsoever you could inevitably figure out how to unpack this format yourself and better yet it hasn't really changed in 46 years (as of 2023.)

More info: https://en.wikipedia.org/wiki/Cpio

5
  • After re-reading your question, I gather you're just at a loss for understanding with regards to the ionice command; this command simply sets system I/O prioritization settings for the subsequent command from the man ionice page: -c2 (class 2, best effort; The priority within the best-effort class will be dynamically derived from the CPU nice level of the process: io_priority = (cpu_nice + 20) / 5) -n5 (class data, priority 5, where 0 is the highest and 7 is the lowest) Commented Dec 27, 2023 at 16:50
  • Something I also wanted to mention about tar is if you don't have an aversion to using it, then also specifying -p (--preserve) it will record the file attributes (permissions, owner) but perhaps not to the same extent that getfacl will. The only problem with preserving permissions across filesystems (for example, from ext4 to NTFS) is whether or not the permissions can or will be preserved upon copy for lack of having any compatibility between the two; they're different filesystems and NTFS on Linux support has not always been what it is today in 2023. FAT32 doesn't support ACLs at all AFAIK. Commented Dec 27, 2023 at 16:55
  • Moreover if you use things like IMA/EVM and SELinux, the getfattr command will also allow you to backup file attributes supported by xattr, tar supports xattr with the additional --xattrs parameter, but also getfattr and setfattr also work much the same way as getfacl and setfacl and as always I recommend reading the man pages about these things because they can tell you a lot more than I can in ~1000 characters more info on NTFS xattr range of support: github.com/tuxera/ntfs-3g/wiki/Using-Extended-Attributes Commented Dec 27, 2023 at 17:00
  • 1
    Thank you very much for such a comprehensive answer. I need to digest all that and do some experiments, but I feel quite sure this information definitely contains the answer for my question (and yes, you are right, I has been baffled by this ionice command, now it has become clear as well). Much appreciated! Commented Dec 27, 2023 at 21:05
  • My pleasure I hope you find everything okay :) feel free to reach out if there's any other questions I can answer Commented Dec 27, 2023 at 22:22
0

what is the best approach...

Given the /home which is in LINUX, don't back up to an NTFS partition. Add a second disk, doing so is not expensive these days, format that disk as EXT4 or XFS (something supported by linux).

But, given various limitations and if you just want to use some existing storage space but it's NTFS, then back up /home using tar. The tar file will preserve all permissions then to restore you're home folder just untar. It works well enough for when I need to use an NTFS partition for backup and is a simple way to get around the permission problem with linux and ntfs:

  • /etc/crontab -> 0 1 * * * root /usr/local/backuphome.sh this will run every day at 1am.

  • create the script /usr/local/backuphome.sh with contents shown below

  • chown root.root backuphome.sh; chmod 700 /backuphome.sh

#!/bin/bash today="$(date '+%Y-%m-%d')" tar -cf /ntfsdisk/backup/home_$today.tar /home 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.