[ / / / / / / / / / / / / / ] [ dir / choroy / dcaco / doomer / f / magali / mde / shota / wmafsex ][Options][ watchlist ]

/tech/ - Technology

You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Email
Comment *
File
Select/drop/paste files here
Password (Randomized for file and post deletion; you may also set your own.)
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

File (hide): e415f48cff9f89f⋯.png (94.96 KB, 706x686, 353:343, Unix_manual.png) (h) (u)

[–]

 No.1021560>>1021615 >>1021626 [Watch Thread][Show All Posts]

I need some help writing a .bash file for Mac that backs up photos on a extern HDD. I have some criterias:

- I should only need to run one single file and then it does all the backup work for me

- I want it to run in the background

- It shall search for all photos (.jpeg types are fine unless Mac uses different file types as well) and back them up in their original folder structure

- It should only search for places you would usually place your photos in a Mac (like a photo folder, the desktop folder, different drives etc.)

- If a single file or more fails to backup it shouldn't give me a notice and just keep on going (again I want it to run silently in the background)

- It should back it all up on the extern HDD I've attached to the Mac under a folder called "PhotoBackup"

- It should copy hidden files as well

- Each time I run it it shall only add photos added since last time it was run

So basicly it's just a backup code that makes sure that all photos I have on my laptop is copied onto my HDD with the same folder structure. I've made this for PC, but I haven't got the skills to do it with Mac. Here's my .bat code (notice I have a script making it run as a hidden process):

@echo off

title Checking file integrities...

:: variables

SET odrive=%odrive:~0,2%

set backupcmd=xcopy /s /c /d /h /i /r /y /exclude:%drive%\excludelist.txt

echo off

%backupcmd% "%USERPROFILE%\*.jpg" "%drive%\backup"

%backupcmd% "D:\*.jpg" "%drive%\backup\drive D"

%backupcmd% "E:\*.jpg" "%drive%\backup\drive E"

@echo off

cls

If someone can make this work I would be thrilled. I'm even willing to pay for your trouble...

 No.1021567>>1021649

sir we will take the job ,,, how much will u be paying and when do u need it by ,, our first couse of action will be to make a logo ,, .... and then we make a program in Java to do the backups


 No.1021575>>1021579 >>1021812

You have a Mac with Bash shell, but you're writing a Windows batch file. Is this correct? The simple solution would be something like this.

find . -type f -name "*.jpg" -exec mv {} newpath \;


 No.1021579

>>1021575

shit that should be cp not mv


 No.1021600>>1021623

install open bsd


 No.1021615

>>1021560 (OP)

You have a mac... whyy fuck around with bash scripting? use time machine.


 No.1021623

>>1021600

/thread


 No.1021626

>>1021560 (OP)

What you'd likely be willing to pay to someone who could do this competently would be insultingly low.

Look into rsync and figure out how to script it yourself.


 No.1021627

Go back to Pooverflow, faggot.


 No.1021649


 No.1021812>>1021830 >>1021861

>>1021575

>find . -type f -name "*.jpg" -exec mv {} newpath \;


find / -type f -name "*{.jpg,.JPG,.jpeg,.JPEG,.tiff,.TIFF,.raw,.RAW}" -exec cp -a {} newpath \;
"find /" to search from the drive root instead of current directory "find . "
{..jpeg...RAW..etc} to match other filetypes and lettercases
cp -a to archival copy while preserving attributes

Insert into a script and put an entry for the script into cron to execute periodically as needed.


 No.1021825

>Mac

Gno


 No.1021830>>1021833

>>1021812

Extended globbing doesn't work in find, gnewfriend.


 No.1021833>>1021839

>>1021830

then use -iregex option instead


 No.1021839

>>1021833

Or just grep -Ex, you know.


 No.1021861

>>1021812

I wouldn't start find from root either. He's probably better off using rsync and keeping his images in the right folder.


 No.1021876

man rsync


 No.1021934

I recommend something like `find` to search and filter a list of items to `rsync`. Once you've got this working as you'd like, you can make an agent for `launchd` (the mac's reinvention of `crontab`) and run it on a schedule. This will be the most portable and extendable (e.g., it could be added into another script) solution.

Do NOT use TimeMachine or any GUI program to do this. You will end up with your data trapped in proprietary containers using proprietary file-formats, and the results will be less usable and probably slow to make any use of.

This is really a perfect way to introduce yourself to some shell-scripting and the command-line. It may take you two months to solve the problem on your own, but it'll save you years and thousands of dollars in the future when you've learned to do this kind of thing on your own, to solve all sorts of little problems like this, routinely.

Honestly, I'd recommend you still use the same resources/commands (at least `rsync` and `launchd` if needed) I've mentioned above, only I'd try to get familiar with Python and write a script using Python instead of Bash. If you don't end up writing many scripts in the future (unlikely), debugging an old bash script will be like reading hieroglyphics, whereas, a well written [and concise] Python script can be dang nigh close to English. The real advantage of using Python will be handling command-line arguments (if necessary), parsing strings and finding and filtering the files you want without esoteric shell commands whose options and arguments are going to be troubling to understand because their explanations will often be too formal. Personally, I find developing a script like this to be the most practical and efficient to do in Python; it's so easy to see the functions and methods and get some quick, offline help via the interpreter (using Python3 and tab-completion). Finally, you can also use Python on Windows (easier than bash). While I'd recommend a cursory familiarity with bash scripting because it'll basically be the language you speak to your computer when you've become accustomed to the CLI, writing scripts in Python has far greater utility and leverage.

You've already laid out your criteria, so it seems like you've given the problem some thought, and you're thinking about it in the appropriate manner, which is far beyond the average user's request for support. Just treat each of those criteria as a comment of pseudo-code and try to unravel how to translate each to actual code (Hint: The majority of this "unraveling" is basically going to be reading the manual pages for the listed programs and figuring out which options and arguments you need to pass in order to be able to filter out exactly what you need, or searching stackoverflow for "how to do x in python"). Your first script is going to be long and shitty, but that's okay. It's how you learn. What you will first write, which will do maybe 80-90% of what you need in 50 lines will one day be reduced to a thorough one-liner when you reach a greater level of competency, and you'll laugh and cry when you look back on the monstrosity that was your first script, but you'll smile on yourself for having taken that first step.




[Return][Go to top][Catalog][Screencap][Nerve Center][Cancer][Update] ( Scroll to new posts) ( Auto) 5
17 replies | 0 images | Page ???
[Post a Reply]
[ / / / / / / / / / / / / / ] [ dir / choroy / dcaco / doomer / f / magali / mde / shota / wmafsex ][ watchlist ]