iconv module (to use with rsync) to avoid windows-illegal filenames in local NTFS partition ...

Why did the IBM 650 use bi-quinary?

Bonus calculation: Am I making a mountain out of a molehill?

Is there a documented rationale why the House Ways and Means chairman can demand tax info?

What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?

Is there a service that would inform me whenever a new direct route is scheduled from a given airport?

Why does Python start at index 1 when iterating an array backwards?

List *all* the tuples!

Why is "Consequences inflicted." not a sentence?

How do I stop a creek from eroding my steep embankment?

Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?

How to bypass password on Windows XP account?

Right-skewed distribution with mean equals to mode?

How widely used is the term Treppenwitz? Is it something that most Germans know?

How can whole tone melodies sound more interesting?

Storing hydrofluoric acid before the invention of plastics

Models of set theory where not every set can be linearly ordered

How to deal with a team lead who never gives me credit?

Is high blood pressure ever a symptom attributable solely to dehydration?

If 'B is more likely given A', then 'A is more likely given B'

How to draw this diagram using TikZ package?

When is phishing education going too far?

What LEGO pieces have "real-world" functionality?

What do you call a plan that's an alternative plan in case your initial plan fails?

What would be the ideal power source for a cybernetic eye?



iconv module (to use with rsync) to avoid windows-illegal filenames in local NTFS partition



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
2019 Community Moderator Election Results
Why I closed the “Why is Kali so hard” questioncase-insensitive search of duplicate file-namesPartition wiped out possibly due to the partition table changed by Windows, malicious software, or …?Will Linux use NTFS as correctly as windows?Mounting a hibernated Windows 8 NTFS partition on Linux MintPermissions with writing NTFS partition from Windowsrsync with colons in filenamesBacking up Linux server to Windows domainMount 'hibernated' windows partition, ciphered with bitlockerntfs issue with rsync: read errors mapping permission denied (13)find and rsync both choke on oddly named fileNo such file or directory during rsync/cp copy command





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







1















I would like to locally attach an NTFS volume to my unix (Ubuntu) machine, and copy (replicate) some unix directories to it, using rsync, in a way that the result is readable under Windows.



I do not care about ownership and permissions. It would be nice if modification dates would be preserved. I only need directories and files (symbolic links would be nice, too; but not a problem if they cannot be copied).



Two obvious problems are: case (in)sensitivity, and characters that are illegal in Windows filenames. For example, in Linux I can have two files "a" and "A"; I can copy them to the NTFS volume, but in Windows I will be able to access (at most?) one of them. But I am happy to ignore that problem. What I am interested about are illegal characters in Windows filenames, which are <,>,:,",/,,|,?, and * (well, actually also ascii 0-31, but I do not care about that. There might also be problems with files ending in a "."?).



I would like rsync to automatically "rename", e.g., a file called "a:"
to, say a(COLON), to end up with a legal name
(and, ideally, translate a(COLON) back to a:)



Is this possible to have rsync automatically rename files to avoid characters forbidden in Windows?




  • As far as I understand rsync can use iconv to do such tasks; is there a standard iconv module for windows-filenames? (I briefly looked into programming an own gconv module, but lacking C knowlege this seems too complicated).

  • I have been told that rdiff-backup can do some conversions like that, but the homepage just mentions something being done "automatically", and I am not sure whether a locally mounted NTFS vomlume would trigger a renaming in a reliable way?

  • I am aware that there is fuse-posixovl, but this seems an overkill for my purpose, and also it doesn't seem to be well documented (which characters will be translated in which way? Will all filenames be truncated to 8.3 or whatever? Can I avoid the additional files carrying owner/permission information, which I will not need, etc etc.)

  • I am aware that I could avoid all these problems by using, e.g., a tar file; but this is not what I want. (In particular, I would like in Windows to further replicate from the NTFS volume to another backup partition, copying only the changed files)

  • I am aware of the "windows_names" option when mounting NTFS; but this will prevent creating offending files, not rename them.


Update: As it seems my question was not quite clear, let me give a more explicit example:
For example, WINDOWS-1251 is of no use for me. iconv -f utf-8 -t WINDOWS-1251//TRANSLIT
transforms



123 abc ABC äö &:<!|


into



123 abc ABC ao &:<!|


I would need a codepage, windows-filenams, say (which does not exist), that transforms the string into something like



123 abc ABC äö &(COLON)(LT)!(PIPE)


Update 2: I now gave up and renamed the offending files ``by hand'' (i.e., by script). From now on, every time before running rsync, I run a script that checks whether offending filenames exist (but does not automatically deal rename anything); I just use



# find stuff containing forbidden chars
find $MYDIR -regex '.*/[^/]*[<>:*"\|?][^/]*'
# find stuff containing dot as last character (supposedly bad for windows)
find $MYDIR -regex '.*.'
# find stuff that is identical case insensitive
find $MYDIR -print0 | sort -z | uniq -diz | tr '' 'n'


(the last line is from case-insensitive search of duplicate file-names )










share|improve this question
















bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Would convmvfs work for you?

    – Gilles
    Feb 8 '17 at 2:05











  • Thank you for the convmvfs suggestion. But it seems that it uses iconv as well; i.e., it does "universally" (for the whole mount) what rsync can do for the specific rsync operation. Unfortunately I am not aware of an iconv charset that consists of unicode minus the forbidden windows characters (otherwise I could just use this iconv charset in rsync directly, I assume)

    – Jakob
    Feb 8 '17 at 10:01











  • --iconv=utf8,windows-charset but I have no idea what windows use. iconv --list show what is available on your system.

    – user192526
    Feb 8 '17 at 13:05













  • @Bahamut Thanks, this is actually part of my question: Is there an iconv module that corresponds to valid windows filename characters? I am not aware of any traditional codepage that includes unicode characters but not, e.g., ":"; I looked at the available iconv charsets (in particular the ones starting with "windows"), but they all seemed to include ":". On my system (ubuntu) there is no "windows-charset" codepage, btw.

    – Jakob
    Feb 8 '17 at 14:21











  • Maybe better one example rsync -avg --iconv=utf8,WINDOWS-1251 but I don't know which one you need exactly. This one is for kyrillisch. Maybe helpful msdn.microsoft.com/de-de/library/windows/desktop/…

    – user192526
    Feb 8 '17 at 15:13


















1















I would like to locally attach an NTFS volume to my unix (Ubuntu) machine, and copy (replicate) some unix directories to it, using rsync, in a way that the result is readable under Windows.



I do not care about ownership and permissions. It would be nice if modification dates would be preserved. I only need directories and files (symbolic links would be nice, too; but not a problem if they cannot be copied).



Two obvious problems are: case (in)sensitivity, and characters that are illegal in Windows filenames. For example, in Linux I can have two files "a" and "A"; I can copy them to the NTFS volume, but in Windows I will be able to access (at most?) one of them. But I am happy to ignore that problem. What I am interested about are illegal characters in Windows filenames, which are <,>,:,",/,,|,?, and * (well, actually also ascii 0-31, but I do not care about that. There might also be problems with files ending in a "."?).



I would like rsync to automatically "rename", e.g., a file called "a:"
to, say a(COLON), to end up with a legal name
(and, ideally, translate a(COLON) back to a:)



Is this possible to have rsync automatically rename files to avoid characters forbidden in Windows?




  • As far as I understand rsync can use iconv to do such tasks; is there a standard iconv module for windows-filenames? (I briefly looked into programming an own gconv module, but lacking C knowlege this seems too complicated).

  • I have been told that rdiff-backup can do some conversions like that, but the homepage just mentions something being done "automatically", and I am not sure whether a locally mounted NTFS vomlume would trigger a renaming in a reliable way?

  • I am aware that there is fuse-posixovl, but this seems an overkill for my purpose, and also it doesn't seem to be well documented (which characters will be translated in which way? Will all filenames be truncated to 8.3 or whatever? Can I avoid the additional files carrying owner/permission information, which I will not need, etc etc.)

  • I am aware that I could avoid all these problems by using, e.g., a tar file; but this is not what I want. (In particular, I would like in Windows to further replicate from the NTFS volume to another backup partition, copying only the changed files)

  • I am aware of the "windows_names" option when mounting NTFS; but this will prevent creating offending files, not rename them.


Update: As it seems my question was not quite clear, let me give a more explicit example:
For example, WINDOWS-1251 is of no use for me. iconv -f utf-8 -t WINDOWS-1251//TRANSLIT
transforms



123 abc ABC äö &:<!|


into



123 abc ABC ao &:<!|


I would need a codepage, windows-filenams, say (which does not exist), that transforms the string into something like



123 abc ABC äö &(COLON)(LT)!(PIPE)


Update 2: I now gave up and renamed the offending files ``by hand'' (i.e., by script). From now on, every time before running rsync, I run a script that checks whether offending filenames exist (but does not automatically deal rename anything); I just use



# find stuff containing forbidden chars
find $MYDIR -regex '.*/[^/]*[<>:*"\|?][^/]*'
# find stuff containing dot as last character (supposedly bad for windows)
find $MYDIR -regex '.*.'
# find stuff that is identical case insensitive
find $MYDIR -print0 | sort -z | uniq -diz | tr '' 'n'


(the last line is from case-insensitive search of duplicate file-names )










share|improve this question
















bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • Would convmvfs work for you?

    – Gilles
    Feb 8 '17 at 2:05











  • Thank you for the convmvfs suggestion. But it seems that it uses iconv as well; i.e., it does "universally" (for the whole mount) what rsync can do for the specific rsync operation. Unfortunately I am not aware of an iconv charset that consists of unicode minus the forbidden windows characters (otherwise I could just use this iconv charset in rsync directly, I assume)

    – Jakob
    Feb 8 '17 at 10:01











  • --iconv=utf8,windows-charset but I have no idea what windows use. iconv --list show what is available on your system.

    – user192526
    Feb 8 '17 at 13:05













  • @Bahamut Thanks, this is actually part of my question: Is there an iconv module that corresponds to valid windows filename characters? I am not aware of any traditional codepage that includes unicode characters but not, e.g., ":"; I looked at the available iconv charsets (in particular the ones starting with "windows"), but they all seemed to include ":". On my system (ubuntu) there is no "windows-charset" codepage, btw.

    – Jakob
    Feb 8 '17 at 14:21











  • Maybe better one example rsync -avg --iconv=utf8,WINDOWS-1251 but I don't know which one you need exactly. This one is for kyrillisch. Maybe helpful msdn.microsoft.com/de-de/library/windows/desktop/…

    – user192526
    Feb 8 '17 at 15:13














1












1








1








I would like to locally attach an NTFS volume to my unix (Ubuntu) machine, and copy (replicate) some unix directories to it, using rsync, in a way that the result is readable under Windows.



I do not care about ownership and permissions. It would be nice if modification dates would be preserved. I only need directories and files (symbolic links would be nice, too; but not a problem if they cannot be copied).



Two obvious problems are: case (in)sensitivity, and characters that are illegal in Windows filenames. For example, in Linux I can have two files "a" and "A"; I can copy them to the NTFS volume, but in Windows I will be able to access (at most?) one of them. But I am happy to ignore that problem. What I am interested about are illegal characters in Windows filenames, which are <,>,:,",/,,|,?, and * (well, actually also ascii 0-31, but I do not care about that. There might also be problems with files ending in a "."?).



I would like rsync to automatically "rename", e.g., a file called "a:"
to, say a(COLON), to end up with a legal name
(and, ideally, translate a(COLON) back to a:)



Is this possible to have rsync automatically rename files to avoid characters forbidden in Windows?




  • As far as I understand rsync can use iconv to do such tasks; is there a standard iconv module for windows-filenames? (I briefly looked into programming an own gconv module, but lacking C knowlege this seems too complicated).

  • I have been told that rdiff-backup can do some conversions like that, but the homepage just mentions something being done "automatically", and I am not sure whether a locally mounted NTFS vomlume would trigger a renaming in a reliable way?

  • I am aware that there is fuse-posixovl, but this seems an overkill for my purpose, and also it doesn't seem to be well documented (which characters will be translated in which way? Will all filenames be truncated to 8.3 or whatever? Can I avoid the additional files carrying owner/permission information, which I will not need, etc etc.)

  • I am aware that I could avoid all these problems by using, e.g., a tar file; but this is not what I want. (In particular, I would like in Windows to further replicate from the NTFS volume to another backup partition, copying only the changed files)

  • I am aware of the "windows_names" option when mounting NTFS; but this will prevent creating offending files, not rename them.


Update: As it seems my question was not quite clear, let me give a more explicit example:
For example, WINDOWS-1251 is of no use for me. iconv -f utf-8 -t WINDOWS-1251//TRANSLIT
transforms



123 abc ABC äö &:<!|


into



123 abc ABC ao &:<!|


I would need a codepage, windows-filenams, say (which does not exist), that transforms the string into something like



123 abc ABC äö &(COLON)(LT)!(PIPE)


Update 2: I now gave up and renamed the offending files ``by hand'' (i.e., by script). From now on, every time before running rsync, I run a script that checks whether offending filenames exist (but does not automatically deal rename anything); I just use



# find stuff containing forbidden chars
find $MYDIR -regex '.*/[^/]*[<>:*"\|?][^/]*'
# find stuff containing dot as last character (supposedly bad for windows)
find $MYDIR -regex '.*.'
# find stuff that is identical case insensitive
find $MYDIR -print0 | sort -z | uniq -diz | tr '' 'n'


(the last line is from case-insensitive search of duplicate file-names )










share|improve this question
















I would like to locally attach an NTFS volume to my unix (Ubuntu) machine, and copy (replicate) some unix directories to it, using rsync, in a way that the result is readable under Windows.



I do not care about ownership and permissions. It would be nice if modification dates would be preserved. I only need directories and files (symbolic links would be nice, too; but not a problem if they cannot be copied).



Two obvious problems are: case (in)sensitivity, and characters that are illegal in Windows filenames. For example, in Linux I can have two files "a" and "A"; I can copy them to the NTFS volume, but in Windows I will be able to access (at most?) one of them. But I am happy to ignore that problem. What I am interested about are illegal characters in Windows filenames, which are <,>,:,",/,,|,?, and * (well, actually also ascii 0-31, but I do not care about that. There might also be problems with files ending in a "."?).



I would like rsync to automatically "rename", e.g., a file called "a:"
to, say a(COLON), to end up with a legal name
(and, ideally, translate a(COLON) back to a:)



Is this possible to have rsync automatically rename files to avoid characters forbidden in Windows?




  • As far as I understand rsync can use iconv to do such tasks; is there a standard iconv module for windows-filenames? (I briefly looked into programming an own gconv module, but lacking C knowlege this seems too complicated).

  • I have been told that rdiff-backup can do some conversions like that, but the homepage just mentions something being done "automatically", and I am not sure whether a locally mounted NTFS vomlume would trigger a renaming in a reliable way?

  • I am aware that there is fuse-posixovl, but this seems an overkill for my purpose, and also it doesn't seem to be well documented (which characters will be translated in which way? Will all filenames be truncated to 8.3 or whatever? Can I avoid the additional files carrying owner/permission information, which I will not need, etc etc.)

  • I am aware that I could avoid all these problems by using, e.g., a tar file; but this is not what I want. (In particular, I would like in Windows to further replicate from the NTFS volume to another backup partition, copying only the changed files)

  • I am aware of the "windows_names" option when mounting NTFS; but this will prevent creating offending files, not rename them.


Update: As it seems my question was not quite clear, let me give a more explicit example:
For example, WINDOWS-1251 is of no use for me. iconv -f utf-8 -t WINDOWS-1251//TRANSLIT
transforms



123 abc ABC äö &:<!|


into



123 abc ABC ao &:<!|


I would need a codepage, windows-filenams, say (which does not exist), that transforms the string into something like



123 abc ABC äö &(COLON)(LT)!(PIPE)


Update 2: I now gave up and renamed the offending files ``by hand'' (i.e., by script). From now on, every time before running rsync, I run a script that checks whether offending filenames exist (but does not automatically deal rename anything); I just use



# find stuff containing forbidden chars
find $MYDIR -regex '.*/[^/]*[<>:*"\|?][^/]*'
# find stuff containing dot as last character (supposedly bad for windows)
find $MYDIR -regex '.*.'
# find stuff that is identical case insensitive
find $MYDIR -print0 | sort -z | uniq -diz | tr '' 'n'


(the last line is from case-insensitive search of duplicate file-names )







windows rsync ntfs fuse rdiff-backup






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 13 '17 at 12:37









Community

1




1










asked Feb 7 '17 at 14:53









JakobJakob

1065




1065





bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Would convmvfs work for you?

    – Gilles
    Feb 8 '17 at 2:05











  • Thank you for the convmvfs suggestion. But it seems that it uses iconv as well; i.e., it does "universally" (for the whole mount) what rsync can do for the specific rsync operation. Unfortunately I am not aware of an iconv charset that consists of unicode minus the forbidden windows characters (otherwise I could just use this iconv charset in rsync directly, I assume)

    – Jakob
    Feb 8 '17 at 10:01











  • --iconv=utf8,windows-charset but I have no idea what windows use. iconv --list show what is available on your system.

    – user192526
    Feb 8 '17 at 13:05













  • @Bahamut Thanks, this is actually part of my question: Is there an iconv module that corresponds to valid windows filename characters? I am not aware of any traditional codepage that includes unicode characters but not, e.g., ":"; I looked at the available iconv charsets (in particular the ones starting with "windows"), but they all seemed to include ":". On my system (ubuntu) there is no "windows-charset" codepage, btw.

    – Jakob
    Feb 8 '17 at 14:21











  • Maybe better one example rsync -avg --iconv=utf8,WINDOWS-1251 but I don't know which one you need exactly. This one is for kyrillisch. Maybe helpful msdn.microsoft.com/de-de/library/windows/desktop/…

    – user192526
    Feb 8 '17 at 15:13



















  • Would convmvfs work for you?

    – Gilles
    Feb 8 '17 at 2:05











  • Thank you for the convmvfs suggestion. But it seems that it uses iconv as well; i.e., it does "universally" (for the whole mount) what rsync can do for the specific rsync operation. Unfortunately I am not aware of an iconv charset that consists of unicode minus the forbidden windows characters (otherwise I could just use this iconv charset in rsync directly, I assume)

    – Jakob
    Feb 8 '17 at 10:01











  • --iconv=utf8,windows-charset but I have no idea what windows use. iconv --list show what is available on your system.

    – user192526
    Feb 8 '17 at 13:05













  • @Bahamut Thanks, this is actually part of my question: Is there an iconv module that corresponds to valid windows filename characters? I am not aware of any traditional codepage that includes unicode characters but not, e.g., ":"; I looked at the available iconv charsets (in particular the ones starting with "windows"), but they all seemed to include ":". On my system (ubuntu) there is no "windows-charset" codepage, btw.

    – Jakob
    Feb 8 '17 at 14:21











  • Maybe better one example rsync -avg --iconv=utf8,WINDOWS-1251 but I don't know which one you need exactly. This one is for kyrillisch. Maybe helpful msdn.microsoft.com/de-de/library/windows/desktop/…

    – user192526
    Feb 8 '17 at 15:13

















Would convmvfs work for you?

– Gilles
Feb 8 '17 at 2:05





Would convmvfs work for you?

– Gilles
Feb 8 '17 at 2:05













Thank you for the convmvfs suggestion. But it seems that it uses iconv as well; i.e., it does "universally" (for the whole mount) what rsync can do for the specific rsync operation. Unfortunately I am not aware of an iconv charset that consists of unicode minus the forbidden windows characters (otherwise I could just use this iconv charset in rsync directly, I assume)

– Jakob
Feb 8 '17 at 10:01





Thank you for the convmvfs suggestion. But it seems that it uses iconv as well; i.e., it does "universally" (for the whole mount) what rsync can do for the specific rsync operation. Unfortunately I am not aware of an iconv charset that consists of unicode minus the forbidden windows characters (otherwise I could just use this iconv charset in rsync directly, I assume)

– Jakob
Feb 8 '17 at 10:01













--iconv=utf8,windows-charset but I have no idea what windows use. iconv --list show what is available on your system.

– user192526
Feb 8 '17 at 13:05







--iconv=utf8,windows-charset but I have no idea what windows use. iconv --list show what is available on your system.

– user192526
Feb 8 '17 at 13:05















@Bahamut Thanks, this is actually part of my question: Is there an iconv module that corresponds to valid windows filename characters? I am not aware of any traditional codepage that includes unicode characters but not, e.g., ":"; I looked at the available iconv charsets (in particular the ones starting with "windows"), but they all seemed to include ":". On my system (ubuntu) there is no "windows-charset" codepage, btw.

– Jakob
Feb 8 '17 at 14:21





@Bahamut Thanks, this is actually part of my question: Is there an iconv module that corresponds to valid windows filename characters? I am not aware of any traditional codepage that includes unicode characters but not, e.g., ":"; I looked at the available iconv charsets (in particular the ones starting with "windows"), but they all seemed to include ":". On my system (ubuntu) there is no "windows-charset" codepage, btw.

– Jakob
Feb 8 '17 at 14:21













Maybe better one example rsync -avg --iconv=utf8,WINDOWS-1251 but I don't know which one you need exactly. This one is for kyrillisch. Maybe helpful msdn.microsoft.com/de-de/library/windows/desktop/…

– user192526
Feb 8 '17 at 15:13





Maybe better one example rsync -avg --iconv=utf8,WINDOWS-1251 but I don't know which one you need exactly. This one is for kyrillisch. Maybe helpful msdn.microsoft.com/de-de/library/windows/desktop/…

– user192526
Feb 8 '17 at 15:13










1 Answer
1






active

oldest

votes


















0














A pragmatic solution would be to reproduce the source directories with the desired converted filenames locally, using hard links to the original files, then rsync this copy as-is to the ntfs filesystem.



For example, this perl script demo duplicates the hierarchy /tmp/a/ into /tmp/b/ and url-encodes (with % and 2 hex digits) the undesirable characters so file:b becomes file%3ab (a hard link) and directory %b<ha> becomes directory %25b%3cha%3e and so on:



#!/usr/bin/perl
use strict;
use File::Find;
my $startdir = '/tmp/a';
my $copydir = '/tmp/b';
sub handlefile{
my $name = substr($File::Find::name,1);
my $oldname = $startdir.$name;
$name =~ s/([;, t+%&<>:"\|?*])/sprintf('%%%02x',ord($1))/ge;
$name = $copydir.$name;
printf "from %s to %sn",$oldname,$name;
if(!-l and -d){ mkdir($name) or die $!; }
else{ link($oldname,$name) or die $!; }
}
chdir($startdir) or die;
find(&handlefile, '.');


You can then rsync /tmp/b to your ntfs. This is just a demo, and needs work for unicode and other limitations of ntfs like max filename length. You could also check for lowercase/uppercase clashes , and use your preferred encoding (: to COLON and so on). You could do a second pass to fix the timestamps on the directories. Unless you have millions of files, the work needed to create this copy of the directory structure, with hard links to the files, should not be that onerous.






share|improve this answer
























  • Thank you very much for the suggestion. However, the solution doesn't seem quite optimal: It seems that for the whole thing to run reliably, I have to remove the whole copydir tree every time I run the script, and then re-run it (or alternatively, check whether the file/dir still exists in the source, and if not remove it; i.e.; doing stuff that I hope rsync would do for me). As I am thinking of a large partition (~ 1TB, ~1Mio files) and I would like to rsync regulalry, this seems a bit inefficient.... Still, I will come back to this if I can't find anything more efficient...

    – Jakob
    Feb 8 '17 at 19:32












Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f343189%2ficonv-module-to-use-with-rsync-to-avoid-windows-illegal-filenames-in-local-ntf%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














A pragmatic solution would be to reproduce the source directories with the desired converted filenames locally, using hard links to the original files, then rsync this copy as-is to the ntfs filesystem.



For example, this perl script demo duplicates the hierarchy /tmp/a/ into /tmp/b/ and url-encodes (with % and 2 hex digits) the undesirable characters so file:b becomes file%3ab (a hard link) and directory %b<ha> becomes directory %25b%3cha%3e and so on:



#!/usr/bin/perl
use strict;
use File::Find;
my $startdir = '/tmp/a';
my $copydir = '/tmp/b';
sub handlefile{
my $name = substr($File::Find::name,1);
my $oldname = $startdir.$name;
$name =~ s/([;, t+%&<>:"\|?*])/sprintf('%%%02x',ord($1))/ge;
$name = $copydir.$name;
printf "from %s to %sn",$oldname,$name;
if(!-l and -d){ mkdir($name) or die $!; }
else{ link($oldname,$name) or die $!; }
}
chdir($startdir) or die;
find(&handlefile, '.');


You can then rsync /tmp/b to your ntfs. This is just a demo, and needs work for unicode and other limitations of ntfs like max filename length. You could also check for lowercase/uppercase clashes , and use your preferred encoding (: to COLON and so on). You could do a second pass to fix the timestamps on the directories. Unless you have millions of files, the work needed to create this copy of the directory structure, with hard links to the files, should not be that onerous.






share|improve this answer
























  • Thank you very much for the suggestion. However, the solution doesn't seem quite optimal: It seems that for the whole thing to run reliably, I have to remove the whole copydir tree every time I run the script, and then re-run it (or alternatively, check whether the file/dir still exists in the source, and if not remove it; i.e.; doing stuff that I hope rsync would do for me). As I am thinking of a large partition (~ 1TB, ~1Mio files) and I would like to rsync regulalry, this seems a bit inefficient.... Still, I will come back to this if I can't find anything more efficient...

    – Jakob
    Feb 8 '17 at 19:32
















0














A pragmatic solution would be to reproduce the source directories with the desired converted filenames locally, using hard links to the original files, then rsync this copy as-is to the ntfs filesystem.



For example, this perl script demo duplicates the hierarchy /tmp/a/ into /tmp/b/ and url-encodes (with % and 2 hex digits) the undesirable characters so file:b becomes file%3ab (a hard link) and directory %b<ha> becomes directory %25b%3cha%3e and so on:



#!/usr/bin/perl
use strict;
use File::Find;
my $startdir = '/tmp/a';
my $copydir = '/tmp/b';
sub handlefile{
my $name = substr($File::Find::name,1);
my $oldname = $startdir.$name;
$name =~ s/([;, t+%&<>:"\|?*])/sprintf('%%%02x',ord($1))/ge;
$name = $copydir.$name;
printf "from %s to %sn",$oldname,$name;
if(!-l and -d){ mkdir($name) or die $!; }
else{ link($oldname,$name) or die $!; }
}
chdir($startdir) or die;
find(&handlefile, '.');


You can then rsync /tmp/b to your ntfs. This is just a demo, and needs work for unicode and other limitations of ntfs like max filename length. You could also check for lowercase/uppercase clashes , and use your preferred encoding (: to COLON and so on). You could do a second pass to fix the timestamps on the directories. Unless you have millions of files, the work needed to create this copy of the directory structure, with hard links to the files, should not be that onerous.






share|improve this answer
























  • Thank you very much for the suggestion. However, the solution doesn't seem quite optimal: It seems that for the whole thing to run reliably, I have to remove the whole copydir tree every time I run the script, and then re-run it (or alternatively, check whether the file/dir still exists in the source, and if not remove it; i.e.; doing stuff that I hope rsync would do for me). As I am thinking of a large partition (~ 1TB, ~1Mio files) and I would like to rsync regulalry, this seems a bit inefficient.... Still, I will come back to this if I can't find anything more efficient...

    – Jakob
    Feb 8 '17 at 19:32














0












0








0







A pragmatic solution would be to reproduce the source directories with the desired converted filenames locally, using hard links to the original files, then rsync this copy as-is to the ntfs filesystem.



For example, this perl script demo duplicates the hierarchy /tmp/a/ into /tmp/b/ and url-encodes (with % and 2 hex digits) the undesirable characters so file:b becomes file%3ab (a hard link) and directory %b<ha> becomes directory %25b%3cha%3e and so on:



#!/usr/bin/perl
use strict;
use File::Find;
my $startdir = '/tmp/a';
my $copydir = '/tmp/b';
sub handlefile{
my $name = substr($File::Find::name,1);
my $oldname = $startdir.$name;
$name =~ s/([;, t+%&<>:"\|?*])/sprintf('%%%02x',ord($1))/ge;
$name = $copydir.$name;
printf "from %s to %sn",$oldname,$name;
if(!-l and -d){ mkdir($name) or die $!; }
else{ link($oldname,$name) or die $!; }
}
chdir($startdir) or die;
find(&handlefile, '.');


You can then rsync /tmp/b to your ntfs. This is just a demo, and needs work for unicode and other limitations of ntfs like max filename length. You could also check for lowercase/uppercase clashes , and use your preferred encoding (: to COLON and so on). You could do a second pass to fix the timestamps on the directories. Unless you have millions of files, the work needed to create this copy of the directory structure, with hard links to the files, should not be that onerous.






share|improve this answer













A pragmatic solution would be to reproduce the source directories with the desired converted filenames locally, using hard links to the original files, then rsync this copy as-is to the ntfs filesystem.



For example, this perl script demo duplicates the hierarchy /tmp/a/ into /tmp/b/ and url-encodes (with % and 2 hex digits) the undesirable characters so file:b becomes file%3ab (a hard link) and directory %b<ha> becomes directory %25b%3cha%3e and so on:



#!/usr/bin/perl
use strict;
use File::Find;
my $startdir = '/tmp/a';
my $copydir = '/tmp/b';
sub handlefile{
my $name = substr($File::Find::name,1);
my $oldname = $startdir.$name;
$name =~ s/([;, t+%&<>:"\|?*])/sprintf('%%%02x',ord($1))/ge;
$name = $copydir.$name;
printf "from %s to %sn",$oldname,$name;
if(!-l and -d){ mkdir($name) or die $!; }
else{ link($oldname,$name) or die $!; }
}
chdir($startdir) or die;
find(&handlefile, '.');


You can then rsync /tmp/b to your ntfs. This is just a demo, and needs work for unicode and other limitations of ntfs like max filename length. You could also check for lowercase/uppercase clashes , and use your preferred encoding (: to COLON and so on). You could do a second pass to fix the timestamps on the directories. Unless you have millions of files, the work needed to create this copy of the directory structure, with hard links to the files, should not be that onerous.







share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 8 '17 at 17:10









meuhmeuh

32.5k12255




32.5k12255













  • Thank you very much for the suggestion. However, the solution doesn't seem quite optimal: It seems that for the whole thing to run reliably, I have to remove the whole copydir tree every time I run the script, and then re-run it (or alternatively, check whether the file/dir still exists in the source, and if not remove it; i.e.; doing stuff that I hope rsync would do for me). As I am thinking of a large partition (~ 1TB, ~1Mio files) and I would like to rsync regulalry, this seems a bit inefficient.... Still, I will come back to this if I can't find anything more efficient...

    – Jakob
    Feb 8 '17 at 19:32



















  • Thank you very much for the suggestion. However, the solution doesn't seem quite optimal: It seems that for the whole thing to run reliably, I have to remove the whole copydir tree every time I run the script, and then re-run it (or alternatively, check whether the file/dir still exists in the source, and if not remove it; i.e.; doing stuff that I hope rsync would do for me). As I am thinking of a large partition (~ 1TB, ~1Mio files) and I would like to rsync regulalry, this seems a bit inefficient.... Still, I will come back to this if I can't find anything more efficient...

    – Jakob
    Feb 8 '17 at 19:32

















Thank you very much for the suggestion. However, the solution doesn't seem quite optimal: It seems that for the whole thing to run reliably, I have to remove the whole copydir tree every time I run the script, and then re-run it (or alternatively, check whether the file/dir still exists in the source, and if not remove it; i.e.; doing stuff that I hope rsync would do for me). As I am thinking of a large partition (~ 1TB, ~1Mio files) and I would like to rsync regulalry, this seems a bit inefficient.... Still, I will come back to this if I can't find anything more efficient...

– Jakob
Feb 8 '17 at 19:32





Thank you very much for the suggestion. However, the solution doesn't seem quite optimal: It seems that for the whole thing to run reliably, I have to remove the whole copydir tree every time I run the script, and then re-run it (or alternatively, check whether the file/dir still exists in the source, and if not remove it; i.e.; doing stuff that I hope rsync would do for me). As I am thinking of a large partition (~ 1TB, ~1Mio files) and I would like to rsync regulalry, this seems a bit inefficient.... Still, I will come back to this if I can't find anything more efficient...

– Jakob
Feb 8 '17 at 19:32


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f343189%2ficonv-module-to-use-with-rsync-to-avoid-windows-illegal-filenames-in-local-ntf%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

Ayherre Geografie Demografie Externe links Navigatiemenu43° 23′ NB, 1° 15′ WL43° 23′ NB, 1°...