-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2e5f0fe
Showing
302 changed files
with
95,337 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 9d07f5f3b0222b1686d473f94bc7f2b2 | ||
tags: d77d1c0d9ca2f4c8421862c7c5a0d620 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# 目的: 使用 rsync 命令备份指定目录 | ||
# 作者: 姚家园、田冬冬 | ||
# 最近修改日期: 2021年2月2日 | ||
# | ||
# 免责声明: | ||
# 本脚本完全基于编写者在自己的计算机上备份文件的经验总结, | ||
# 并不具备普遍适用性,仅供读者参考。 | ||
# | ||
|
||
source="${HOME}" # 源目录 | ||
backup="/mnt/seismo-learn/backup" # 备份目录(通常为移动硬盘的挂载目录) | ||
log="${backup}/backup.log" # 备份目录下的备份日志 | ||
|
||
# 检查源目录 | ||
if [ ! -d "${source}" ]; then # 源目录不存在,退出程序 | ||
echo "[${source}] does not exist!" | ||
exit | ||
elif [ -z "$(ls ${source})" ]; then # 源目录是空目录,退出程序 | ||
echo "[${source}] is empty!" | ||
exit | ||
fi | ||
|
||
# 列出需要备份的目录 | ||
dirs=( ${source}/* ) # 备份源目录下所有子目录(不含隐藏目录和文件) | ||
# dirs=( # 仅备份源目录下部分子目录 | ||
# "${source}/src" | ||
# "${source}/software" | ||
# "${source}/codes" | ||
# ) | ||
|
||
# 若备份目录不存在,则新建 | ||
mkdir -p "${backup}" | ||
|
||
# 备份开始时间 | ||
echo "## Backup begins at $(date +%F-%H:%M:%S)" >> "${log}" | ||
|
||
# 按序备份每个目录 | ||
for dir in "${dirs[@]}"; do | ||
echo -e "------------------------------------------\n" | ||
echo -e "Backup ${dir}\n" | ||
echo "Backup ${dir} at $(date +%F-%H:%M:%S)" >> "${log}" | ||
rsync -av --delete "${dir}" "${backup}" | ||
done | ||
|
||
# 备份结束时间 | ||
echo -e "## Backup ends at $(date +%F-%H:%M:%S)\n\n" >> "${log}" | ||
|
||
# 检查备份目录下是否存在源目录下已删除的目录 | ||
echo -e "\n++++++++++++++++++++++++++++++++++++++++++++\n" | ||
echo -e "Backup is finished! Begin to check!\n" | ||
flag=1 | ||
dirs_backup=( ${backup}/* ) | ||
for dir_backup in "${dirs_backup[@]}"; do | ||
# 忽略备份日志 | ||
dir_name=$(basename "${dir_backup}") | ||
if [ "${dir_backup}" = "${log}" ]; then | ||
continue | ||
fi | ||
|
||
# 备份目录下存在源目录下已删除的目录 | ||
if [ ! -d "${source}/${dir_name}" ]; then | ||
echo "[${dir_name}] is deleted in [${source}] but is still in [${backup}]." | ||
flag=0 | ||
fi | ||
done | ||
|
||
if [ ${flag} = 0 ]; then | ||
echo "You may choose to delete them in [${backup}] later." | ||
else | ||
echo "Backup is successful!" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
REM | ||
REM 目的: 使用 robocopy 命令备份指定目录 | ||
REM 作者: 赵志远、李天觉 | ||
REM 最近修改日期: 2021年2月7日 | ||
REM | ||
REM 免责声明: | ||
REM 本脚本完全基于编写者在自己的计算机上备份文件的经验总结, | ||
REM 并不具备普遍适用性,仅供读者参考。 | ||
REM | ||
|
||
REM 源目录和备份目录 | ||
REM D:\directory、D:\代码、D:\项 目 : 要备份的源目录 | ||
REM F:\backup : 备份目录 | ||
|
||
REM robocopy 命令常用选项: | ||
REM /mir : 备份目录成为镜像 (复制子目录;删除备份目录下源目录中不存在的文件和目录) | ||
REM /mt[:n] : 使用 n 个线程进行多线程复制(默认值为 8)。n 至少为 1,但不得大于 128。 | ||
REM 例如,/mt 表示 8 个线程,/mt:4 表示 4 个线程 | ||
REM 可以参考 https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/robocopy | ||
REM 了解 robocopy 命令的更多用法。例如,也可以使用正文中备份 D 盘是所用的 | ||
REM 一些选项 /R:10 /W:10 /A-:H /XD Config.Msi $RECYCLE.BIN | ||
|
||
REM 注意事项: | ||
REM 1. 如果脚本中存在中文,需要采用 ANSI 编码格式,否则会乱码。 | ||
REM 2. 若目录名存在空格,必须加引号,如 "D:\项 目" | ||
|
||
echo "备份 D:\directory 到 F:\backup\directory" | ||
robocopy D:\directory F:\backup\directory /mir /mt | ||
pause | ||
|
||
echo "备份 D:\代码 到 F:\backup\代码" | ||
robocopy D:\代码 F:\backup\代码 /mir /mt | ||
pause | ||
|
||
echo "备份 D:\项 目 到 F:\backup\项 目" | ||
robocopy "D:\项 目" "F:\backup\项 目" /mir /mt | ||
pause |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Linux 数据备份 | ||
|
||
- 本节贡献者: {{田冬冬}}(作者)、{{姚家园}}(作者) | ||
- 最近更新日期: 2021-10-01 | ||
- 预计阅读时间: 20 分钟 | ||
|
||
--- | ||
|
||
新买的移动硬盘的文件系统一般是 NTFS 或 exFAT。推荐将移动硬盘文件系统 | ||
设置为 Linux 系统的常见格式 ext4,用于 Linux 下的文件备份。 | ||
该格式在 Ubuntu、Debian、Fedora、CentOS 等 Linux 发行版下,可以保持文件权限。 | ||
在 Linux 系统下,可以使用 `mkfs` 命令将移动硬盘设置为 Linux 文件系统。还可以 | ||
使用 `e2label` 命令为移动硬盘设置卷标。 | ||
|
||
## rsync | ||
|
||
使用 `rsync` 命令进行备份十分方便。假设用户名为 seismo-learn,移动硬盘下的备份目录 | ||
为 {file}`/mnt/seismo-learn/backup/` 。使用以下命令可以将家目录下的所有子目录和文件 | ||
完整同步到备份目录下,此时备份目录是家目录的一个镜像: | ||
|
||
``` | ||
$ rsync -av --delete /home/seismo-learn/ /mnt/seismo-learn/backup/ | ||
``` | ||
|
||
:::{important} | ||
以上命令中家目录 {file}`/home/seismo-learn/` 最后的斜杠非常重要。若没有这个斜杠 | ||
({file}`/home/seismo-learn`),则会把家目录本身同步到备份目录下, | ||
即产生 {file}`/mnt/seismo-learn/backup/seismo-learn` 目录。 | ||
::: | ||
|
||
`rsync` 命令的特色在于增量备份。这意味着只有第一次备份的时候需要花比较多的时间来 | ||
同步文件,之后再使用该命令进行备份只会同步有改动的文件。假如一周只修改了一个文件, | ||
那么同步的过程会在瞬间完成。 | ||
|
||
读者可以参考 Bash 脚本 {download}`backup.sh`。点击下载后,修改源目录、 | ||
备份目录以及想要备份的子目录。然后按以下命令,修改文件权限为可执行, | ||
并将脚本移至 {file}`~/bin` 目录下,就可以运行了: | ||
|
||
``` | ||
# 修改可执行权限 | ||
$ chmod +x backup.sh | ||
# 移动至 ~/bin/ 目录 | ||
$ mv backup.sh ~/bin | ||
# 执行命令开始备份 | ||
$ backup.sh | ||
``` | ||
|
||
## DejaDup | ||
|
||
[DejaDup](https://wiki.gnome.org/Apps/DejaDup) 是一款很好的图形界面备份工具。 | ||
|
||
安装 DejaDup: | ||
|
||
::::{tab-set} | ||
|
||
:::{tab-item} Fedora | ||
:sync: fedora | ||
|
||
``` | ||
$ sudo dnf install deja-dup | ||
``` | ||
::: | ||
|
||
:::{tab-item} CentOS | ||
:sync: centos | ||
|
||
``` | ||
$ sudo yum install deja-dup | ||
``` | ||
::: | ||
|
||
:::{tab-item} Ubuntu/Debian | ||
:sync: ubuntu-debian | ||
|
||
``` | ||
$ sudo apt update | ||
$ sudo apt install deja-dup | ||
``` | ||
::: | ||
:::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Windows 数据备份 | ||
|
||
- 本节贡献者: {{赵志远}}(作者)、{{姚家园}}(作者) | ||
- 最近更新日期: 2021-10-01 | ||
- 预计阅读时间: 20 分钟 | ||
|
||
--- | ||
|
||
## robocopy | ||
|
||
使用 Windows 自带的 [robocopy](https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/robocopy) | ||
命令进行增量备份。这意味着只有第一次备份的时候需要花比较多的时间来同步文件,之后再使用该命令进行备份 | ||
只会同步有改动的文件。假设要备份整个 D 盘,移动硬盘下的备份目录为 {file}`F:\\backup`。 | ||
打开 CMD 或 PowerShell,使用以下命令可以将 D 盘同步到备份目录下,此时备份目录是 D 盘的一个镜像: | ||
|
||
``` | ||
$ robocopy D:\ F:\backup /mir /mt /R:10 /W:10 /A-:H /XD Config.Msi $RECYCLE.BIN | ||
``` | ||
|
||
:::{important} | ||
以上命令中 D 盘盘符后的反斜杠({file}`D:\\`)非常重要,省略的话可能无法备份整个 D 盘。 | ||
|
||
`/XD` 选项后的目录(如 {file}`Config.Msi`、{file}`$RECYCLE.BIN`) | ||
在备份时被忽略。读者可以根据自己的实际情况把无法备份或者不想备份的目录添加到此选项后。 | ||
::: | ||
|
||
读者可以参考 Batch 脚本 {download}`backup.bat`。点击下载后,修改源目录、备份目录以及想要 | ||
备份的子目录。然后,双击该 Batch 脚本即可直接运行。也可以打开 CMD 或 PowerShell, | ||
再输入 Batch 脚本名以运行脚本。 | ||
|
||
## Backup | ||
|
||
:::{warning} | ||
本节尚未开始编写。读者可以参考 <https://www.portableone.com/Tech-News/Microsoft-Windows-10-PCs-have-their-own-Apple-Time-Machine-feature> | ||
使用 Windows 10 Backup,欢迎提供反馈。 | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# macOS 数据备份 | ||
|
||
- 本节贡献者: {{田冬冬}}(作者)、{{姚家园}}(作者) | ||
- 最近更新日期: 2021-10-01 | ||
- 预计阅读时间: 20 分钟 | ||
|
||
--- | ||
|
||
## Time Machine | ||
|
||
macOS 下最好用的备份工具当属 Time Machine(时间机器),其可以增量备份 macOS 下的文件, | ||
能恢复到之前任意备份时刻的状态,并且操作简单。当然也可以使用 `rsync` 命令进行备份, | ||
与 Linux 下相同。推荐使用 Time Machine 进行备份。 | ||
|
||
首先插入一块备用硬盘,按下 {kbd}`Command` + {kbd}`空格`,搜索“Disk Utility”并按下 | ||
{kbd}`Enter` 键以打开磁盘工具。将移动硬盘格式化成 APFS(加密)格式,这也是 macOS Big Sur(11.x) | ||
的默认格式。读者可以根据自身情况选择分区大小,推荐至少是 macOS 本身硬盘空间的两倍。 | ||
|
||
点击左上角的 Apple 图标,在“系统偏好设置”中,打开“时间机器”。选中“在菜单栏中显示时间机器”。 | ||
点击“选择备份磁盘”,从可用磁盘列表中选择之前格式化的硬盘分区,然后选择“使用磁盘”即可。 | ||
时间机器会立即开始备份。首次备份可能需要很长时间,之后只会同步有改动的文件。下次插入备份硬盘, | ||
直接从菜单栏的时间机器菜单中选择“立即备份”即开始增量备份。可以选择“进入时间机器”,查看备份内容。 | ||
如需还原备份文件,请参考官方支持[从备份恢复 Mac](https://support.apple.com/zh-cn/HT203981)。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# 数据备份 | ||
|
||
- 本节贡献者: {{姚家园}}(作者)、{{田冬冬}}(作者) | ||
- 最近更新日期: 2021-10-01 | ||
- 预计阅读时间: 5 分钟 | ||
|
||
--- | ||
|
||
**备份!备份!备份!** | ||
|
||
尽管不经常发生,但电脑随时可能会坏掉或被盗,电脑硬盘也随时可能会出问题, | ||
也可能不小心使用一个命令(如 `rm -r *`)把几个月的工作误删了。所以,备份非常重要, | ||
不进行必要的备份是十分危险的。笔者和一些同行多次体验过数据误删或硬盘损坏 | ||
又未备份带来的痛苦。 | ||
|
||
如果**文件非常重要**,丢失后**恢复难度极大**,或**恢复时间极长**, | ||
强烈推荐备份一下。例如,毕业论文、脚本、代码、电脑配置文件、无法再次获取的数据、 | ||
经过长时间处理得到的资料。 | ||
|
||
:::{warning} | ||
日常科研工作中,电脑硬盘经常进行大量的读写操作,直接影响硬盘的寿命。我们的 | ||
经验表明,电脑硬盘的平均寿命大约为 5 年。当然,硬盘的品质和使用情况不同, | ||
其寿命也有所不同。 | ||
::: | ||
|
||
备份策略简单概括有两种:(1)备份家目录或其部分子目录;(2)全盘备份。 | ||
|
||
不同备份策略的主要区别在于备份所需的硬盘空间和时间,以及电脑硬盘摔坏带来的损失。 | ||
移动硬盘是最常见的备份设备,其特点是携带方便、价格便宜。近几年,移动硬盘发展迅速, | ||
市场上常见的移动硬盘,其存储空间大小有 1 TB 到 5 TB(单价从 300 到 800 块左右), | ||
基本可以满足日常科研的备份需求。一般而言,第一次备份需要较长时间,后续的备份往往 | ||
只同步改动过的文件,所需时间较短。考虑以上两点因素以及硬盘摔坏带来的精神和身体上的损失, | ||
我们推荐备份家目录或者至少备份家目录下重要的子目录。有需求的用户可以考虑全盘备份。 | ||
|
||
有效的文件备份并不是简单的复制和同步文件。复制存储在同一个硬盘中的文件不是备份,硬盘 | ||
一旦出现问题所有的文件都可能丢失。和计算机放在一块的移动硬盘可能因为火灾、盗窃等 | ||
原因一起丢失。有效备份方案的几个核心特性是:版本控制、删除重复文件、安全性。 | ||
对备份实施版本控制保证了用户可以从任何备份过的历史版本中恢复文件。删除源文件中的重复文件, | ||
可以减少存储开销。在安全性方面,应该考虑他人需要什么工具和信息或者发生什么意外 | ||
才会完全删除源文件和备份。此外,不要盲目信任备份方案,应该经常检查备份是否可以用来恢复文件。 | ||
|
||
除了使用移动硬盘备份文件以外,还可以将部分文件同时备份到云端,多一份保障。例如,将程序和脚本等 | ||
推送到 [GitHub](https://github.com/) 上,将部分文件同步到网盘(如百度网盘、 | ||
OneDrive、Google Drive、Dropbox、iCloud 等)。需要注意,若误删本地文件, | ||
云端可能会同步这些“更改”;一些应用可能有时或永久无法登录,造成云端备份文件暂时或永久性丢失。 | ||
因此,最好把云端备份当作本地移动硬盘备份的补充,而不是重要文件的唯一备份。 | ||
|
||
建议每隔一段时间(如每周)做一次备份。放假前、出差开会前,也建议备份一下。 |
Oops, something went wrong.