Copy only file reference using rsync - linux

I'm trying to sync two directories, but with a catch: I want my destination folder to have a zero byte file if the corresponding full file exists in the source. Is this possible using rsync or is there any other linux alternative?

Related

Renaming a file without copying it; any alternative to OverlayFS?

I want to have a "virtual" filesystem like OverlayFS where I can rename the files and folders, but without copying the whole file. I have an archive with over 800TB of Data and the files need to be renamed, but I want to keep the original folder structure and the filenames.
For instance:
I have the 800tb mount on /mnt/archive.
I want an "overlay" mount on /mnt/archive_renamed.
So that a file, for example Data001.bin on /mnt/archive can be renamed on the overlaymount and look something like this /mnt/archive_renamed/Data_from_2014/Data_from_Cats.bin but belongs still to Data001.bin and never touches the underlying mount.
OverlayFS would be perfect if it doesn't need to copy the whole file when renaming it.
Any clue?
In /mnt/archive_renamed, you can use hardlinks to the original files.
Just do "cp -al /mnt/archive /mnt/archive_renamed" and you'll have to folders pointing to the same files.

Copy file from windows to linux without Modifying file timestamp using SAS

I want to copy excel file file from windows to Linux system and need to capture last modified date of the file.
We cant take take last modified date of the file from windows.
Since i am using below code to copy file from Windows to Linux, Code is able to transfer file to Linux system however once after running the code the timestamp of the file is changing. Is there any way to copy file from windows to linux without modifying file timestamp. Please help.
%smb_init(username=**MYID**, password=%str(**password**), domain=**aa.aaa.com**);
%smb_load();
%smb_pull(windows=//files/Load/Test/Folder1/PIC Alerts/ABC Alerts.xlsx,
linux=/sasdata/test_files/folder2/ABC_Alerts.xlsx);
If you would like to copy files while preserving attributes, enable X commands in SAS and let the OS handle copying files. After enabling it, it's as simple as using a built-in Linux file copying command like rsync.
For example, this will copy data, attributes, and timestamps:
rsync -av //source/mydata.xlsx /dest/mydata.xlsx
Once you confirm it works as expected, you can build it into your SAS program and pass it to Linux:
x 'rsync -av //source/mydata.xlsx /dest/mydata.xlsx';
The automatic macro variable &sysrc will tell you if it was successful. A value of 0 means success. Non-zero means failure.

File extracted on windows and then copied to linux - any issue in file format on LINUX

Wanted to understand if a zip file is extracted on windows and then extracted files are copied (WINSCP) to LINUX machine.
l there be any issue on Linux related to file format ?
scp does not transform the file in any way; there is no difference between extracting the file on one system and transferring it to the destination system via scp versus extracting the file directly on the destination system (assuming no transfer errors occur).

How to create a copy of a directory on Linux with links

I have a series of directories on Linux and each directory contains lots of files and data. The data in those directories are automatically generated, but multiple users will need to perform more analysis on that data and generate more files, change the structure, etc.
Since these data directories are very large, I don't want several people to make a copy of the original data so I'd like to make a copy of the directory and link to the original from the new one. However, I'd like any changes to be kept only in the new directory, and leave the original read only. I'd prefer not to link only specific files that I define because the data in these directories is so varied.
So I'm wondering if there is a way to create a copy of a directory by linking to the original but keeping any changed files in the new directory only.
It turns out this is what I wanted to:
cp -al <origdir> <newdir>
It will copy an entire directory and create hard links to the original files. If the original file is deleted, the copied file still exists, and vice-versa. This will work perfectly, but I found newdir must not already exist. As long as the original files are read-only, you'll be able to create an identical, safe copy of the original directory.
However, since you are looking for a way that people can write back changes, UnionFS is probably what you are looking for. It provides means to combine read-only and read-write locations into one.
Unionfs allows any mix of read-only and read-write branches, as well as insertion and deletion of branches anywhere in the fan-out.
Originally I was going to recommend this (I use it a lot):
Assuming the permissions aren't an issue (e.g. only reading is required) I would suggest to bind-mount them into place.
mount -B <original> <new-location>
# or
mount --bind <original> <new-location>
<new-location> must exist as a folder.

Apply exact stat parameters from one file to another using C in Linux

I would like get stat parameters from one file and later apply it as is, to a copy of the same file (Including type, path, permissions, size, etc.).
The original file will be long gone from this directory and the copy will take his place, and should get the same exact properties.
How could this be done using C in Linux?
If I understand your question correctly, you don't need to write your own program to do that.
If your files reside on the same machine, you can preserve and restore times and permissions in tar archives. The p option handles permissions, and times are persisted by default (except atime, but --atime-preserve can work around that).
Alternatively, if you want to restore files from a remote server, you can use rsync with the -a option.

Resources