Appendix III. How to Backup

Scheduled task: crontab

Linux crontab是用来定期执行程序的命令。

在线crontab生成器

Edit .bashrc file in the $HOME directory

EDITOR=vi; export EDITOR

Create a file called usercron (space separated)

15 1 * * * /bin/echo 'date' > /dev/console

Running file

crontab usercron

Column

Mean

Column 1:

Minutes 0 to 59

Column 2:

Hours 0 to 23 (0 means midnight)

Column 3:

Day 1 to 31

Column 4:

Months 1~12

Column 5:

Week 0 to 7 (0 and 7 for Sunday)

Column 6:

Command to run

Execute my Command every 1 minute

* * * * * Command

Execute at 3 and 15 minutes from 1 am

3,15 1 * * * Command

Restart smb at 1:30 every night

30 1 * * * /etc/init.d/smb restart

List the crontab file with the -l parameter:

$ crontab -l
0,15,30,45 18-06 * * * /bin/echo `date` > dev/tty1

Edit crontab file

$ crontab -e

crontab file to make a backup

$ crontab -l > $HOME/mycron

Remote data synchronization tool: rsync

rsync命令是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件。

Synchronize data on local disk

rsync -a --delete /home /backups

Perform a "push" copy sync

rsync /etc/hosts user@172.22.220.21:/home/xugang/hosts

Perform a "pull" replication synchronization

rsync user@172.22.220.21:/home/xugang/hosts /etc/hosts
rsync -aqzH --delete --delay-updates \
user@172.22.220.21:/home/xugang/hosts /etc/hosts

mirror centos at 0:10 AM everyday

10 0 * * * rsync -aqzH –delete \
--delay-updates user@172.22.220.21:/home/xugang/hosts /etc/hosts

Parameter

Mean

-a:

以递归方式传输文件

--delete:

删除那些接收端还有而发送端已经不存在的文件

-q:

精简输出模式

-z:

在传输文件时进行压缩处理

-H:

保持硬链接文件

-t:

对比两边文件的时间戳和文件大小.如果一致,则就认为两边文件一样,对此文件就不再采取更新动作了

-I:

挨个文件去发起数据同步

--port=PORT:

端口号

How to automatically enter a password when logging in to the system

1. Generate SSH key

ssh-keygen -t rsa -b 2048

2. Copy your keys to the target server:

ssh id@server
vi .ssh/authorized_keys

Backup your code: GitHub

Create your new repository on GitHub

create a new repository on the command line

echo "# test" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/xug15/test.git
git push -u origin master

Download repository

git clone https://github.com/xug15/test.git

Save the change of your codes.

git add *
git add –u .
git commit -m ‘20190705v1’

Update your codes into the GitHub

git push origin master
Username for 'https://github.com': xug15
Password for 'https://xug15@github.com':

Auto update bash

time=`date`
echo $time
git add -u .
git add *
git commit -m '$time'
git push origin master

Use GitHub Desktop App

Cloud storage

  • Nextcloud 实验室内部搭建的云存储。找实验室管理人员开通账户。

  • Tsinghua cloud 清华云,在校内使用速度快。

  • Nutstore cloud 商业云存储,每个月有免费的备份流量。自己申请账号使用。

Backup tool that comes with the system

Mac: Back up your Mac with Time Machine

Windows: How to back up or transfer your data on a Windows-based computer