如何在 Mac 中创建批处理文件? [英] How to create a batch file in Mac?

查看:201
本文介绍了如何在 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.

我基本上想要实现的是一个自动化的任务,可以用一个可执行文件运行,它可以:

  1. 将特定目录 (/Volumes/Audio/Shoko) 压缩为 rar 或 zip 文件.

  1. compress a specific directory (/Volumes/Audio/Shoko) to a rar or zip file.

(在 zip 文件中排除所有子目录和目录名称视频"中的所有 *.wav 文件).

将其移动到网络共享(/Volumes/Post Shared/Backup From Sound).

move It to a network share (/Volumes/Post Shared/Backup From Sound).

(或直接压缩到此文件夹).

使用动态日期和时间自动生成 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.

我尝试将 Mark 的 bash 行(来自下面的第一个答案)放在一个 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?

我想要一个有效的例子:)

I would love a working example :)

谢谢,

戴夫

推荐答案

您可以制作一个 bash 脚本来进行备份,然后您可以双击它或按计划运行它.我不知道你的路径和/或选择的工具,但有些事情是这样的:

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" .

您可以将其保存在桌面上作为 backup,然后进入终端并输入:

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.

此外,您可能更喜欢使用其他一些工具 - 例如 rsync,但方法是相同的.

Also, you may prefer to use some other tools - such as rsync but the method is the same.

这篇关于如何在 Mac 中创建批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆