如何创建Mac的批处理文件? [英] How to create a batch file in Mac?
问题描述
我每天需要在工作中找到一个解决方案备份特定的文件夹,希望为RAR或ZIP文件。
I need to find a solution at work to backup specific folders daily, hopefully to a RAR or ZIP file.
如果它是在PC上,我就已经做到了。但是,我没有任何想法如何处理它在Mac上。
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:
-
COM preSS特定的目录(
/卷/音频/祥子
)为RAR或ZIP文件。
compress a specific directory (
/Volumes/Audio/Shoko
) to a rar or zip file.
(在zip文件中排除所有子目录中的所有* .wav文件和目录名视频)。
将其移动到网络共享( /卷/后共享/备份从声音
)。
move It to a network share (/Volumes/Post Shared/Backup From Sound
).
(或COM preSS直接到该文件夹)。
自动动态日期和时间(所以没有重复的文件名)Zip文件的文件名。
automate the file name of the Zip file with dynamic date and time (so no duplicate file names).
关机Mac的完成时。
我要再说一遍,我通常不使用的是Mac,所以像什么样的文件来打开脚本,而这样的东西是不平凡的我,还没有。
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.
我试图把马克的庆典线(从第一个答案,下同)在一个txt文件并执行它,但它有错误,没有工作。
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.
我也尝试过使用的Automator,但它太平淡,没有先进的选项。
I also tried to use Automator, but it's too plain, no advanced options.
我怎样才能做到这一点?
How can I accomplish this?
我喜欢工作的例子:)
感谢你,
戴夫
推荐答案
您可以只是做一个庆典
脚本,并备份,然后您可以双击它或按计划运行。我不知道你的路径和/或选择的工具,但沿着这些线路的一些事情:
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.
此外,您可能preFER使用一些其他的工具 - 比如的rsync
但该方法是一样的。
Also, you may prefer to use some other tools - such as rsync
but the method is the same.
这篇关于如何创建Mac的批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!