I want to make backups of a directory, everything the same as original files, only except for file content converting to all zeros (sparse files), and also keep the same file size. So for example, I have
- dir/file1 with 1 GB non-zero data
- dir/file2 with 2 GB non-zero data
- ... (the dir is large enough with many more files and sub-directories)
and I need
- dir_bak/file1 with exactly same metadata as dir/file1.txt and 1 GB zeros (or corresponding sparse file)
- dir_bak/file2 with exactly same metadata as dir/file2.txt and 2 GB zeros (or corresponding sparse file)
- ...
The result files as well as sub-directory structure should be compressed as an archive (preferred) or sparsely stored, so only little disk space would be used.
One key matter here is that I have no more disk space to make a full backup, so please don't come up with solutions like making a full backup first and processing it later. During the whole process please also don't use up too much extra disk space.
FYI, it's on ext4, linux with basic shell command (like ls
, find
, cp
, tar
, dd
, truncate
, etc.) support.
P.S. Any other kind of backup/snapshot/image/archive solution, meeting the demand (empty content with full metadata), than shell script is welcome, too.