Page 1 of 1

[Mysolved] Backup with checksum comparison.

Posted: 07 Oct 2019 21:46
by eil
i hope i did search properly, 'cause i didn't find some script to be close to my needs(which actually made me surpriced). so i hope smb can help me with at least parts of code.

i'm in need of script that backups list of items to target folder, while checking if there are collisions. in case of collision files need to be compared by checksum. same checksum = no action/skip file, otherwise rename existing with adding modified date suffix to name and copy new.
eventually it will look like: file.ext, file-<modified_date>.ext, file-<modified_date>.ext, etc. so i need to have some way of cheking "suffixed files overload". if number of suffixed files(with same name but different suffixes) exceeds the number set in variable - delete the oldest suffixed file.

Re: [Request] Backup with checksum comparison.

Posted: 07 Oct 2019 22:14
by highend
Then show the code you've already done and describe where exactly you're having a problem?

Re: [Request] Backup with checksum comparison.

Posted: 07 Oct 2019 22:55
by eil
you understood it wrong, i ment if maybe people know other scripts that have parts with similar actions, so i could research them to understand how to make mine. have no code for now.

Re: [Request] Backup with checksum comparison.

Posted: 07 Oct 2019 23:02
by highend
Sorry but I don't get the real problem. It's a loop over <some> files, maybe from the current folder.
A simple if/else if the file already exists in the destination folder
If it does not exist, copy it
If it does exist, compare checksums of both and depending on if they match
They match: Do nothing
They don't:
Do the renaming of the original file
Test how many files in the destination folder exists, that have the same base + the modified date part
Count them
If they are over the limit, sort them descending, delete the last one(s)
Copy the file...

The only "difficult" part (for a novice) is the "get files with the same base" because it should be done with a regex...

Re: [Mysolved] Backup with checksum comparison.

Posted: 10 Oct 2019 19:11
by eil
after whole DAY of being noob but figuring out how to do this "simple", finally made it. so i thank me very much, especially for solving it without regex. :maf:

Re: [Mysolved] Backup with checksum comparison.

Posted: 10 Oct 2019 19:21
by highend
so, share the code?