Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard way, across operating systems, of adding "tags" to files

I'm writing a script to make backups of various different files. What I'd like to do is store meta information about the backup. Currently I'm using the file name, so for example:

backups/cool_file_bkp_c20120119_104955_d20120102

Where c represents the file creation datetime, and d represents "data time" which represents what the cool_file actually contains. The reason I currently use "data time" is that a later backup may be made of the same file, in which case, I know I can safely replace the previous backup of the same "data time" without loosing any information.

It seems like an awful way to do things, but it does seem to have the benefit of being non-os dependent. Is there a better way?

FYI: I am using Python to script my backup creation, and currently need to have this working on Windows XP, 2003, and Redhat Linux.

EDIT: Solution: From the answers below, I've inferred that metadata on files is not widely supported in a standard way. Given my goal was to tightly couple the metadata with the file, it seems that archiving the file alongside a metadata textfile is the way to go.

like image 284
cammil Avatar asked Oct 08 '22 23:10

cammil


2 Answers

I'd take one of two approaches there:

create a stand alone file, on the backub dir, that would contain the desired metadata - this could be somethnng in human readable form, just to make life easier, such as a json data structure, or "ini" like file.

The other one is to archive the copied files - possibily using "zip", and bundle along with it a textual file with the desired meta-data.

The idea of creating zip archives to group files that you want together is used in several places, like in java .jar files, Open Document Format (offfice files created by several office sutres), Office Open XML (Microsoft specific offic files), and even Python language own eggs.

The ziplib module in Python's standard library has all the toools necessary to acomplish this - you can just use a dictionary's representation in a file bundled with the original one to have as much metadata as you need.

In any of these approaches you will also need a helper script to letyou see and filter the metadata on the files, of course.

like image 80
jsbueno Avatar answered Oct 16 '22 00:10

jsbueno


Different file systems (not different operating systems) have different capabilities for storing metadata. NTFS has plenty of possibilities, while FAT is very limited, and ext* are somewhere in between. None of widespread (subjective term, yes) filesystems support custom tags which you could use. Consequently there exists no standard way to work with such tags. On Windows there was an attempt to introduce Extended Attributes, but these were implemented in such a tricky way that were almost unusable.

So putting whatever you can into the filename remains the only working approach. Remember that filesystems have limitations on file name and file path length, and with this approach you can exceed the limit, so be careful.

like image 39
Eugene Mayevski 'Callback Avatar answered Oct 16 '22 01:10

Eugene Mayevski 'Callback