I'm trying to build a automatic backup solution. My AppleScript commands are pretty simple. All I want to do is copy all the files in one folder to a different folder.
Currently I'm using this:
rsync --update -raz --progress Documents/test "Volumes/RFM_Projects_2"
This works when I have my files located in a folder called test in the Documents folder. Problem is that I have a different folder structure now where I have all the files I want to copy on a second internal harddrive.
I thought it would be easy to just change "Documents/test" to something like "Volumes/WORK/test", but this does not work at all.
Any ideas about how I can change the source location to a secondary harddrive?
All slash-delimited style paths, like the ones used in your rsync command, must start with a slash (/). That slash stands for the startup volume drive. I do not see that first slash in any of your paths so I'm surprised any of your code ever worked. Here's an applescript which will show you the path. Run this, select any folder you want, and copy/paste the result into your code. Note that if there are any spaces in any of your paths then you should put your paths in quotes in your rsync command.
choose folder
return POSIX path of result
Also note if you want the path to a file instead of a folder then change the word folder to file in the applescript. Good luck.
Related
So I'm trying to create basic directory and push it out across our end users. I've got the basic .cmd to work but it breaks when I have a folder with multiple spaces.
cmd /c mkdir "C:\ProgramData\Example\This Folder Has Four Spaces\Example"
the plan is to set this to run automatically on machines.. If I remove the path with the long folder name, it works perfectly fine. Is there a way for me to place a file in the directory that has a long folder name with spaces? I wasn't sure if there was any sort of bypass to this. I initially thought it was because I was trying to copy a file to the program data folder but I've tested this with other folder names and it works fine. Just seems to be this specific folder it doesn't work with so I'm led to believe it's because of how long the folder name is.
I could not find a usable solution to this seemingly simple problem, despite my best efforts.
I'm using MacOS High Sierra 10.13.6
I have a folder I want to copy with the following location:
/Users/ep9k/Desktop/Key-LogEcovaluator/whereami
I want to copy it to this directory using the terminal:
/Users/ep9k/Library/Application/Support/QGIS/QGIS3/profiles/default/python/plugins
I tried the following commands in the terminal. Notice I am in the 'whereami' folder when doing this:
whereami ep9k$ cp -r /Users/ep9k/Desktop/Key-LogEcovaluator/whereami /Users/ep9k/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins
whereami ep9k$ cp -a /Users/ep9k/Desktop/Key-LogEcovaluator/whereami /Users/ep9k/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins
I'm met with the following message indicating I am not using it correctly:
However, I created a "tester" folder on my desktop and can copy to this folder with no problems, using exactly the same command (except with the pathname changed to my tester folder).
I can also copy and paste things to this directory using the GUI "finder". What am I missing?
Your destination path contains at least one whitespace character ("Application Support"), which causes the "cp" command to think it's being given three arguments instead of two. Enclose the destination path in single or double quotes and you should be all right.
The following Python script:
import os
print os.listdir('D:\images')
is outputing the names of all the folders in the D:\image directory, but it is also showing desktop.ini in the same folder, while there is no such file in the image directory.
Its also not a hidden item, I am sure of that.
Why is it then showing it as a content?
desktop.ini is a protected system file, and Windows tends to hide it.
You can verify by going to D:\images in a terminal and running dir /A.
See this answer as well.
You can use os.walk() if you want more control, it will give you directories and files separately. You can also use os.path.isdir() to find out if an entry you get is a directory.
I used os.path.isdir(path) to check whether the item returned by os.listdir() is a directory or not
This way,desktop.ini didn't meet the criteria of being a directory and my program scanned all the folders.
I need to find a solution at work to backup specific folders daily, hopefully to a RAR or ZIP file.
If it was on PC, I would have done it already. But I don't have any idea to how to approach it on a Mac.
What I basically want to achieve is an automated task, that can be run with an executable, that does:
compress a specific directory (/Volumes/Audio/Shoko) to a rar or zip file.
(in the zip file exclude all *.wav files in all sub Directories and a directory names "Videos").
move It to a network share (/Volumes/Post Shared/Backup From Sound).
(or compress directly to this folder).
automate the file name of the Zip file with dynamic date and time (so no duplicate file names).
Shutdown Mac when finished.
I want to say again, I don't usually use Mac, so things like what kind of file to open for the script, and stuff like that is not trivial for me, yet.
I have tried to put Mark's bash lines (from the first answer, below) in a txt file and executed it, but it had errors and didn't work.
I also tried to use Automator, but it's too plain, no advanced options.
How can I accomplish this?
I would love a working example :)
Thank You,
Dave
You can just make a bash script that does the backup and then you can either double-click it or run it on a schedule. I don't know your paths and/or tools of choice, but some thing along these lines:
#!/bin/bash
FILENAME=`date +"/Volumes/path/to/network/share/Backup/%Y-%m-%d.tgz"`
cd /directory/to/backup || exit 1
tar -cvz "$FILENAME" .
You can save that on your Desktop as backup and then go in Terminal and type:
chmod +x ~/Desktop/backup
to make it executable. Then you can just double click on it - obviously after changing the paths to reflect what you want to backup and where to.
Also, you may prefer to use some other tools - such as rsync but the method is the same.
I have a folder containing many other sub-folders.
I am trying to write a batch file which will copy some of the folders to another place on my hard disk. I am using "xcopy" for this. I am facing following problem:
The folder structure is as shown below-
--FolderB1
---FolderB2
---FolderB22
---File1.txt
---File2.txt
---File3.txt
I have some .txt files inside "FolderB1", along with "FolderB2" and
"FolderB22" I want to copy "FolderB2" and "FolderB22" and skip ".txt"
files contained in "Folder B1"
I tried using /EXCLUDE: param of xcopy command, but it is not able to perform this operation. It does not work if I specify the exclusion as \FolderB1\*.txt or something of this sort.
The number of main folders is not known. It can be anything. Also, there is no fix pattern for names of ".txt" files. Have checked this question too, but did not help.
Alternate method or other pointers for the same would be a great help. Thanks in advance.
What you could try to do is to hide the files you don't want to copy, then execute the xcopy, and then unhide the files again.
Look at my answer of question Windows batch script to delete everything in a folder except one. That question was related do deleting files (excluding some files), but you can probably use the same trick for xcopy-ing files.