备份
用zplup备份oh-my-zsh配置
oh-my-zsh配置通过zplug安装插件,当恢复的时候自动加载没安装的插件。
安装说明
安装:
brew install zplug
1.在 .zshrc 顶部加入 zplug 环境变量
export ZPLUG_HOME=/usr/local/opt/zplug
source $ZPLUG_HOME/init.zsh
2.在 .zshrc 中部编辑插件列表
zplug "插件作者/插件名称"
zplug "zsh-users/zsh-autosuggestions"
自己的为:
#zsh的插件
plugins=()
# zplug插件管理
zplug "plugins/git", from:oh-my-zsh
zplug "plugins/sublime", from:oh-my-zsh
zplug "plugins/autojump", from:oh-my-zsh
zplug "powerlevel9k/powerlevel9k", as:theme, depth:1
zplug "zsh-users/zsh-syntax-highlighting"
zplug 'zplug/zplug', hook-build:'zplug --self-manage'
zplug "zsh-users/zsh-autosuggestions"
3.在 .zshrc 底部写入 zplug 安装命令
if !zplug check --verbose; then
printf "Install? [y/N]: "
if read -q; then
echo; zplug install
fi
fi
zplug load
4.刷新 zsh 配置以生效
source ~/.zshrc
官方插件库:https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins
- powerlevel9k: 我使用的主题
- git: 提供很多 git 的快捷操作
- osx: 在终端控制你的mac,如 spotify 切歌
- vscode: 在 vscode 打开文件 z: 目录跳转 d: 目录跳转
- extract: 解压工具
- git-open:
- sudo: 摁两次esc,在命令前加 sudo
- cp: 安全复制
- web-search: 在终端中 google 或其他搜索引擎
- rand-quote: 随机一句quote,可以放在 zsh 加载的最后一行
- history-substring-search: 查找匹配前缀的历史输入
- command-not-found: This plugin uses the command-not-found package for zsh to provide suggested packages to be installed if a command cannot be found.
- zsh-syntax-highlighting: zsh 高亮
- zsh-autosuggestions: 自动提示输入内容
- gitignore: 快速添加
.gitignore
用brew bundle 备份应用列表
说明
创建备份目录(注意我们是放到icloud的):
mkdir ~/Documents/.backup
备份brew安装包
使用 brew bundle
进行备份,可以备份通过 brew
和 brew cask
以及通过 AppStore
安装的内容(mas)
brew bundle dump --describe --force --file="~/Documents/.backup/backup"
运行该命令,可以获得一份 brew buddle
的备份文件,通过 brew buddle
可以实现一键全部安装
备份Application 目录应用列表
有些 app 不是通过上面提到的三种方法安装的,处理这些漏网之鱼,我选择备份 Application 文件夹的应用列表 $ ls -l /Applications | awk '{print $3"\t", $0}' | sort > ~/Documents/.backup/AppList.txt
获取 Setapp 目录应用列表
$ ls -l /Applications/Setapp | awk '{print $3"\t", $0}' | sort > ~/Documents/.backup/Setapp.txt
用mackup备份应用配置
mackup官网:https://github.com/lra/mackup mackup使用文档:https://github.com/lra/mackup/blob/master/doc/README.md 通过homebrew安装 $ brew install mackup
mackup配置
mackup默认备份到Dropbox,由于我日常用iCloud,所以要修改备份路径。
创建mackup配置文件:$ vi ~/.mackup.cfg
填入配置
[storage]
engine = icloud
directory = Mackup
保存后退出。备份到 iCloudDrive 下的 Mackup
文件夹
用mackup进行配置备份
$ mackup backup
定时备份
利用 crontab 工具进行每日中午12点自动备份
列出 crontab 计划 $ crontab -l
编辑 crontab 计划 $ crontab -e
计划内容:
00 12 * * * ls -l /Applications | awk '{print $3"\t", $0}' | sort > ~/Documents/.backup/AppList.txt && osascript -e 'display notification "~/Documents/.backup/Applist.txt" with title "成功备份 Applist" '
00 12 * * * ls -l /Applications/Setapp | awk '{print $3"\t", $0}' | sort > ~/Documents/.backup/Setapp.txt && osascript -e 'display notification "~/Documents/.backupfile/Setapplist.txt" with title "成功备份 Setapplist" '
01 12 * * * /usr/local/bin/brew bundle dump --describe --force --file=""~/Documents/.backup/backup" && osascript -e 'display notification ""~/Documents/.backup/backup" with title "成功备份 Brewfile" '
02 12 * * * /usr/local/bin/mackup -f backup && osascript -e 'display notification "mackup backup" with title "Mackup 成功备份" '
还原
还原通过 brew 安装的应用和包
安装 homebrew: curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install
安装 mas brew install mas
利用brew buddle还原 brew bundle --file="~/Documents/.backup/backup"
还原 mackup 备份过的应用设置
mackup 安装 brew install mackup
mackup 配置
要修改备份路径。
创建mackup配置文件:
vi ~/.mackup.cfg
填入配置
[storage] engine = icloud
directory = Mackup
保存后退出。mackup 还原: mackup restore
重新安装那些不是通过 brew 安装的应用
打开 ~/Documents/Applist.txt 可以看到自己安装了那些应用,可以作为安装参照
打开 ~/Documents/Setapplist.txt 可以看到自己安装了那些 setapp 应用