一、背景

在我之前的博客 git学习——> Gitlab如何进行备份恢复与迁移? (地址:http://blog.csdn.net/ouyang_peng/article/details/77070977) 里面已经写清楚了如何使用Gitlab自动备份功能。

但是之前的备份功能只是备份到Gitlab服务运行的那台服务器上,如果哪一天那台服务器的磁盘损坏了的话,数据无法取出,那么对于公司来说是一匹无法想象的损失,因为

代码是公司的重要资产,需要以防万一。

代码是公司的重要资产,需要以防万一。

代码是公司的重要资产,需要以防万一。

因此我们得做好代码的备份工作,因此除了每天在Gitlab那台服务器上自动备份之外,还需要将每天的备份文件copy到另外一台文件备份服务器上,已达到双保险的要求。

二、服务器密钥配对,取消scp传输密码限制

远程手动备份数据费时费力且不及时。最好的方法就是通过脚本实现远程自动互备。但远程无论是通过SSH登陆,还是通过scp拷贝文件都需要输入密码。为了克服这个问题,首先需要实现不需要密码的SSH登陆,这样就可以使用 rsync,scp,rexec等命令来做的远程备份了。

前提:本地服务器:A, 远程服务器:B

2.1 生成密钥对

假设A,B两服务器,现在需要在A机上用root登陆B机,而不需要输入密码。那我们可按照下面的步骤来做:

2.1.1 在本地服务器A上生成rsa证书

在本地服务器A上生成rsa证书,运行命令:

ssh-keygen -t rsa

完整运行如下所示:

root@ubuntu4146:/data/gitlabData/backups# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
50:75:d3:53:d7:d8:98:1f:e7:9f:43:19:31:0d:e1:c4 root@ubuntu4146
The key's randomart image is:
+--[ RSA 2048]----+
| ... oo+@*|
| . . +EoB|
| . .+=|
| . oo|
| S . o|
| o.|
| .|
| |
| |
+-----------------+
root@ubuntu4146:/data/gitlabData/backups#

1、生成的过程中提示输入密钥对保存位置,直接回车,接受默认值就行了。

2、因为之前已经有/root/.ssh/id_rsa 文件存在,因此提示你是否覆盖,输入y表示覆盖

3、接着会提示输入一个密码,直接回车,让它空着。当然,也可以输入一个密码。

4、接着输入确认密码,输入完之后,回车密钥对就生成完了。

在/root/.ssh下生成id_rsa 和 id_rsa.pub 两个文件,

其中公共密钥保存在 /root/.ssh/id_rsa.pub,私有密钥保存在/root/.ssh/id_rsa。

2.1.2 在本地服务器A上cp生成rsa公钥证书

然后在/root/.ssh下复制备份一份id_rsa.pub 命名为 id_rsa.pub.A,以便拷贝到远程服务器B。

执行cp命令复制

cp id_rsa.pub id_rsa.pub.A

2.2 cp生成rsa公钥证书到远程服务器B

使用scp命令进行远程复制,将A机生成的id_rsa.pub.A拷贝到远程服务器B的/root/.ssh目录下

root@ubuntu4146:~/.ssh# scp /root/.ssh/id_rsa.pub.A root@远程服务器ip:/root/.ssh/
root@远程服务器ip's password:
id_rsa.pub.A

这里使用scp命令需要输入密码,当我们把下面的第三步执行完毕之后,以后本地服务器A使用scp命令复制文件到远程服务器B的话,就不需要再次输入密码。

三、密钥配对

3.1 创建authorized_keys文件

当第二步将服务器A上的id_rsa.pub.A 文件copy到了服务器B的目录/root/.ssh下之后截图如下:

现在我们在 B 的/root/.ssh下创建authorized_keys文件,使用如下命令

touch authorized_keys

3.2 将id_rsa.pub.A文件内容追加到authorized_keys 文件中

通过 cat 命令 把id_rsa.pub.A 追写到 authorized_keys 文件中,命令依次如下:

cat id_rsa.pub.A >> authorized_keys

3.3 修改authorized_keys文件的权限

执行如下命令,修改authorized_keys文件的权限

chmod 400 authorized_keys

authorized_keys文件的权限很重要,如果设置为777,那么登录的时候,还是需要提供密码的。

3.4 测试

测试服务器A使用scp命令复制文件到服务器B是否还需要密码

在服务A上,再次使用刚才的命令,发现已经可以不需要输入密码,如下所示:

四、创建Shell定时远程备份脚本

4.1 在本地服务器A上创建定时远程备份脚本

本地服务器A上创建定期备份脚本auto_backup_to_remote.sh,脚本内容如下

#!/bin/bash

# gitlab 机房备份路径
LocalBackDir=/data/gitlabData/backups # 远程备份服务器 gitlab备份文件存放路径
RemoteBackDir=/root/gitlabDataBackup # 远程备份服务器 登录账户
RemoteUser=root # 远程备份服务器 IP地址
RemoteIP=(你的远程服务器地址)请自己修改 #当前系统日期
DATE=`date +"%Y-%m-%d"` #Log存放路径
LogFile=$LocalBackDir/log/$DATE.log # 查找 本地备份目录下 时间为60分钟之内的,并且后缀为.tar的gitlab备份文件
BACKUPFILE_SEND_TO_REMOTE=$(find /data/gitlabData/backups -type f -mmin -60 -name '*.tar*') #新建日志文件
touch $LogFile #追加日志到日志文件
echo "Gitlab auto backup to remote server, start at $(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
echo "---------------------------------------------------------------------------" >> $LogFile # 输出日志,打印出每次scp的文件名
echo "---------------------The file to scp to remote server is: $BACKUPFILE_SEND_TO_REMOTE-------------------------------" >> $LogFile #备份到远程服务器
scp $BACKUPFILE_SEND_TO_REMOTE $RemoteUser@$RemoteIP:$RemoteBackDir #追加日志到日志文件
echo "---------------------------------------------------------------------------" >> $LogFile

因为到时候,我们会将该定时远程备份脚本auto_backup_to_remote.sh执行的时间,放到Gitlab自动备份脚本auto_backup.sh之后的一小时之内,因此我们只需要每次执行远程备份脚本auto_backup_to_remote.sh的时候,只需要cp一个小时之内的生成的新的Gitlab备份文件。

4.2 修改定时远程备份脚本auto_backup_to_remote.sh的权限

要执行脚本文件,需要修改定时远程备份脚本auto_backup_to_remote.sh的权限

chmod 777 auto_backup_to_remote.sh

4.3 手动执行脚本

现在为了验证脚本是否可以正常运行,我们需要手动执行脚本。

如上图所示,因为最后一次Gitlab备份时间为凌晨2点,而现在已经是下午3点半左右,因此我们需要修改脚本的查询条件。

将查询条件从 本地备份目录下 时间为60分钟之内的,并且后缀为.tar的gitlab备份文件

# 查找 本地备份目录下 时间为60分钟之内的,并且后缀为.tar的gitlab备份文件
BACKUPFILE_SEND_TO_REMOTE=$(find /data/gitlabData/backups -type f -mmin -1000 -name '*.tar*')

修改为 本地备份目录下 时间为1000分钟之内的,并且后缀为.tar的gitlab备份文件

# 查找 本地备份目录下 时间为1000分钟之内的,并且后缀为.tar的gitlab备份文件
BACKUPFILE_SEND_TO_REMOTE=$(find /data/gitlabData/backups -type f -mmin -1000 -name '*.tar*')

先在终端执行find命令,看是否能够正常查找出我们要scp到远程服务器的Gitlab备份文件

root@ubuntu4146:/data/gitlabData/backups# find /data/gitlabData/backups -type f -mmin -1000  -name '*.tar*'
/data/gitlabData/backups/1502906429_2017_08_17_9.4.3_gitlab_backup.tar

将定时远程备份脚本auto_backup_to_remote.sh修改完毕之后,我们试着手动执行该脚本,看是否能够正常运行。

执行命令

root@ubuntu4146:/data/gitlabData/backups# ./auto_backup_to_remote.sh

执行该脚本文件,在2分钟之内就将最后一次的Gitlab备份文件scp到了远程服务器B

root@ubuntu4146:/data/gitlabData/backups# ./auto_backup_to_remote.sh
1502906429_2017_08_17_9.4.3_gitlab_backup.tar 100% 1337MB 11.2MB/s 01:59

我们切换到远程服务器B,查看刚才从服务器A 通过scp命令复制过来的Gitlab备份文件,如下所示:

[root@xtgl207940 .ssh]# cd /root/gitlabDataBackup/
[root@xtgl207940 gitlabDataBackup]# ll
总用量 1369100
-rw-------. 1 root root 1401958400 8月 17 15:36 1502906429_2017_08_17_9.4.3_gitlab_backup.tar
[root@xtgl207940 gitlabDataBackup]#

至此,从服务器A复制备份文件到服务器B的脚本正常运行,但是如果每次都这样来手动触发脚本的话,太麻烦,因此我们需要定时执行脚本。

五、定时执行脚本

5.1 编辑/etc/crontab 文件

即vi /etc/crontab,然后添加相应的任务。

#编辑 /etc/crontab
vi /etc/crontab

可以看到,这里有我们之前写好的定期凌晨2点执行Gitlab本机备份的定时任务

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do. SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin # m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
# # edited by ouyang 2017-8-11 添加定时任务,每天凌晨两点,执行gitlab备份
0 2 * * * root /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1 #也可以按照如下所示的方法,定时执行 auto_backup.sh脚本,脚本内容就填写: /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
#0 2 * * * root /data/gitlabData/backups/auto_backup.sh -D 1

现在我们在上面的定时任务后面,再添加一个执行复制刚备份好的Gitlab备份文件到服务器B的脚本任务。如下所示:

# edited by ouyang 2017-8-17 添加定时任务,每天凌晨三点,执行gitlab备份到远程服务器
0 3 * * * root /data/gitlabData/backups/auto_backup_to_remote.sh

5.2 重启cron服务

编写完 /etc/crontab 文件之后,需要重新启动cron服务

#重新加载cron配置文件
sudo /usr/sbin/service cron reload
#重启cron服务
sudo /usr/sbin/service cron restart

实际运行如下:

root@ubuntu4146:/data/gitlabData/backups# sudo /usr/sbin/service cron reload
root@ubuntu4146:/data/gitlabData/backups# sudo /usr/sbin/service cron restart
cron stop/waiting
cron start/running, process 47631

5.3 测试自动化脚本

为了能够测试,该脚本是否能够在指定时间的时候,真的能够自动执行,我们将时间修改为15:55分。修改如下:

# edited by ouyang 2017-8-17 添加定时任务,每天凌晨三点,执行gitlab备份到远程服务器
55 15 * * * root /data/gitlabData/backups/auto_backup_to_remote.sh

然后重启cron服务

#重新加载cron配置文件
sudo /usr/sbin/service cron reload
#重启cron服务
sudo /usr/sbin/service cron restart

现在时间是15:58分,我们去查看生成的log文件,可以看到在15:55分的时候,脚本正常定时执行了

Gitlab auto backup to remote server, start at  2017-08-17 15:55:01
---------------------------------------------------------------------------
---------------------The file to scp to remote server is: /data/gitlabData/backups/1502906429_2017_08_17_9.4.3_gitlab_backup.tar-------------------------------
---------------------------------------------------------------------------
Gitlab auto backup to remote server, end at 2017-08-17 15:57:00

切换到远程服务器B,查看从服务器Acopy过来的Gitlab备份文件

通过测试,可以发现定时任务也正常执行了,因此我们可以将时间改为凌晨3点来复制Gitlab备份文件到远程服务器B。

# edited by ouyang 2017-8-17 添加定时任务,每天凌晨三点,执行gitlab备份到远程服务器
0 3 * * * root /data/gitlabData/backups/auto_backup_to_remote.sh

六、定时删除远程服务器上的备份文件

通过如上图所示,每个Gitlab备份文件都很大,都有1G左右的大小。因此每天备份一次,过不了多久的话,备份服务器B上的磁盘空间可能就会被Gitlab备份文件占用完。

因此我们需要定期清理备份文件,清理的时候我们可以自己定义,这里我们规定:

备份文件超过30天的都自动删除掉。

为了实现这个功能,我们需要在远程服务器B上编写脚本来清理过期的备份文件。

6.1 创建定期删除过期的备份文件的脚本

创建定期删除过期的备份文件的脚本auto_remove_old_backup.sh

[root@xtgl207940 gitlabDataBackup]# touch auto_remove_old_backup.sh

6.2 编写脚本auto_remove_old_backup.sh

vi auto_remove_old_backup.sh

脚本内容如下 :

#!/bin/bash

# 远程备份服务器 gitlab备份文件存放路径
GitlabBackDir=/root/gitlabDataBackup # 查找远程备份路径下,超过30天 且文件后缀为.tar 的 Gitlab备份文件 然后删除
find $GitlabBackDir -type f -mtime +30 -name '*.tar*' -exec rm {} \;

6.3 手动执行auto_remove_old_backup.sh脚本

修改auto_remove_old_backup.sh脚本权限为777

chmod 777 auto_remove_old_backup.sh

如上图所示,目前备份服务器上,只有一个8月17日15:56分copy过来的Gitlab备份文件,为了能够测试我们的脚本是否正常运行,我们新建几个7月份的文件,如下所示:

使用touch命令,创建指定时间的 test.tar 文件

[root@xtgl207940 gitlabDataBackup]# touch -t 201707011230 test1.tar
[root@xtgl207940 gitlabDataBackup]# touch -t 201707021230 test2.tar
[root@xtgl207940 gitlabDataBackup]# touch -t 201707031230 test3.tar
[root@xtgl207940 gitlabDataBackup]# touch -t 201707041230 test4.tar
[root@xtgl207940 gitlabDataBackup]# ll
总用量 1369104
-rw-------. 1 root root 1401958400 8月 17 15:56 1502906429_2017_08_17_9.4.3_gitlab_backup.tar
-rwxrwxrwx. 1 root root 279 8月 17 16:24 auto_remove_old_backup.sh
-rw-r--r--. 1 root root 0 7月 1 12:30 test1.tar
-rw-r--r--. 1 root root 0 7月 2 12:30 test2.tar
-rw-r--r--. 1 root root 0 7月 3 12:30 test3.tar
-rw-r--r--. 1 root root 0 7月 4 12:30 test4.tar
[root@xtgl207940 gitlabDataBackup]#

这样我们就创建了4个7月1日到7月4日的的test1.tar、test2.tar、test3.tar、test4.tar

现在我们手动来执行我们的auto_remove_old_backup.sh脚本

[root@xtgl207940 gitlabDataBackup]# ./auto_remove_old_backup.sh
[root@xtgl207940 gitlabDataBackup]# ll
总用量 1369104
-rw-------. 1 root root 1401958400 8月 17 15:56 1502906429_2017_08_17_9.4.3_gitlab_backup.tar
-rwxrwxrwx. 1 root root 279 8月 17 16:24 auto_remove_old_backup.sh
[root@xtgl207940 gitlabDataBackup]#

对比执行auto_remove_old_backup.sh脚本前后,我们发现超过30天的,并且以.tar后缀结尾的文件都被删除了,脚本正常。

七、定时执行删除脚本

7.1 编辑/etc/crontab 文件

即vi /etc/crontab,然后添加相应的任务。

#编辑 /etc/crontab
vi /etc/crontab

然后编写定时任务

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root # For details see man 4 crontabs # Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed # edited by ouyang 2017-8-17 添加定时任务,每天凌晨4点,执行删除过期的Gitlab备份文件
0 4 * * * root /root/gitlabDataBackup/auto_remove_old_backup.sh

7.2 重启crond服务

写完 /etc/crontab 文件之后,需要重新启动cron服务,因为远程备份服务器是Center OS 和之前的Gitlab服务器 Ubuntu 有点不一样,所以重启cron命令有所不同。

#重新加载cron配置文件
sudo service crond reload
#重启cron服务
sudo service crond restart

7.3 测试定期删除任务

为了测试定期删除任务,现在时间是16:35,我们将脚本执行时间设置为16:40分,如下所示

# edited by ouyang 2017-8-17 添加定时任务,每天凌晨4点,执行删除过期的Gitlab备份文件
40 16 * * * root /root/gitlabDataBackup/auto_remove_old_backup.sh

然后重启cron服务,超过16点40分之后我们再查看过期的.tar文件是否被删除

[root@xtgl207940 gitlabDataBackup]# touch -t 201707011230 test1.tar
[root@xtgl207940 gitlabDataBackup]# touch -t 201707021230 test2.tar
[root@xtgl207940 gitlabDataBackup]# touch -t 201707031230 test3.tar
[root@xtgl207940 gitlabDataBackup]# touch -t 201707041230 test4.tar
[root@xtgl207940 gitlabDataBackup]# ll
总用量 1369104
-rw-------. 1 root root 1401958400 8月 17 15:56 1502906429_2017_08_17_9.4.3_gitlab_backup.tar
-rwxrwxrwx. 1 root root 279 8月 17 16:24 auto_remove_old_backup.sh
-rw-r--r--. 1 root root 0 7月 1 12:30 test1.tar
-rw-r--r--. 1 root root 0 7月 2 12:30 test2.tar
-rw-r--r--. 1 root root 0 7月 3 12:30 test3.tar
-rw-r--r--. 1 root root 0 7月 4 12:30 test4.tar
[root@xtgl207940 gitlabDataBackup]# vi /etc/
[root@xtgl207940 gitlabDataBackup]# vi /etc/crontab
[root@xtgl207940 gitlabDataBackup]# sudo service crond reload
Redirecting to /bin/systemctl reload crond.service
[root@xtgl207940 gitlabDataBackup]# sudo service crond restart
Redirecting to /bin/systemctl restart crond.service
[root@xtgl207940 gitlabDataBackup]# ll
总用量 1369104
-rw-------. 1 root root 1401958400 8月 17 15:56 1502906429_2017_08_17_9.4.3_gitlab_backup.tar
-rwxrwxrwx. 1 root root 279 8月 17 16:24 auto_remove_old_backup.sh
[root@xtgl207940 gitlabDataBackup]#

如上所示,我们修改定时执行任务的时间后,删除任务正常执行,因此我们时间修改回凌晨4点删除过期备份文件。

# edited by ouyang 2017-8-17 添加定时任务,每天凌晨4点,执行删除过期的Gitlab备份文件
0 4 * * * root /root/gitlabDataBackup/auto_remove_old_backup.sh


作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!

转载请保留原文地址:http://blog.csdn.net/ouyang_peng/article/details/77334215

如果本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行打赏。

Git学习-->如何通过Shell脚本自动定时将Gitlab备份文件复制到远程服务器?的更多相关文章

  1. Git学习-->如何通过Shell脚本实现 监控Gitlab备份整个过程并且通过邮件通知得到备份结果?

    一.背景 Git学习–>如何通过Shell脚本自动定时将Gitlab备份文件复制到远程服务器? http://blog.csdn.net/ouyang_peng/article/details/ ...

  2. CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存

    CentOS/Linux内存占用大,用Shell脚本自动定时清除/释放内存来自:互联网 时间:2020-03-22 阅读:114以下情况可能造成Linux内存占用过高服务配置存在直接分配错误,或隐性分 ...

  3. Linux学习-->如何通过Shell脚本实现发送邮件通知功能?

    1.安装和配置sendmail 不需要注册公网域名和MX记录(不需要架设公网邮件服务器),通过Linux系统自带的mail命令即可对公网邮箱发送邮件.不过mail命令是依赖sendmail的,所以我们 ...

  4. 使用 shell 脚本自动获取发版指标数据

    问题背景 大一点的公司都会建立一套规章流程来避免低级错误,例如合入代码前必需经过同行评审:上线前必需提测且通过 QA 验证:全量前必需经过 1%.5%.10%.20%.50% 的灰度过程.尤其是最后一 ...

  5. shell脚本自动清理服务器日志、图片等信息

    在做性能测试的时候,linux服务器时常会产生大量数据,如日志信息,图片信息,文件信息等,压测一段时间后,导致服务器磁盘空间暂满而崩溃,每天手动清理比较麻烦, 利用shell脚本自动清理,脚本如下 1 ...

  6. shell 脚本自动插入文件头

    vim编辑shell脚本自动插入文件头部信息,将下面的代码写入home目录xia .vimrc 文件即可. shell 文件头: 1 autocmd BufNewFile *.sh exec &quo ...

  7. 【shell脚本】ftp自动上传mysql备份文件

    上一篇中 mysql每日备份shell脚本 给出了使用mysqldump备份到本地的脚本,接着下面是利用ftp把备份文件传输到远程服务器的脚本. 当然也可以用scp,rsync等等方案. #!/bin ...

  8. Shell脚本自动重启Java服务

    话不多说直接上代码: cd /home/javaProduct/if [ -d '/home/javaProduct/lib_new/' ]; thenecho 'Has New Lib!'echo ...

  9. 使用 shell 脚本自动对比两个安装目录并生成差异补丁包

    问题的提出 公司各个业务线的安装包小则几十兆.大则几百兆,使用自建的升级系统向全国百万级用户下发新版本时,流量耗费相当惊人.有时新版本仅仅改了几个 dll ,总变更量不过几十 K 而已,也要发布一个完 ...

随机推荐

  1. 【Java面试题】51 什么时候用assert。

    assertion(断言)在软件开发中是一种常用的调试方式,很多开发语言中都支持这种机制. 在实现中,assertion就是在程序中的一条语句,它对一个boolean表达式进行检查,一个正确程序必须保 ...

  2. Spring-更多DI的知识

    3.3.1 延迟初始化Bean 延迟初始化也叫做惰性初始化,指不提前初始化Bean,而是只有在真正使用时才创建及初始化Bean. 配置方式很简单只需在<bean>标签上指定 “lazy-i ...

  3. Ubuntu:为 Firefox 浏览器 安装 flash 插件

    从adobe上下载浏览器flashplayer插件:推荐 x.tar.gz格式的——通用格式. 解压tar.gz后可以得到:libflashplayer.so 文件 将 libflashplayer. ...

  4. EasyTouch的使用官方文档操作步骤

    对于移动平台上的RPG类的游戏,我们常用虚拟摇杆来控制人物角色的行走和一些行为,相信我们对它并不陌生,之前尝试了EasyTouch2.5,发现并没有最新版的3.1好用,2.5版本的对于自适应没有做的很 ...

  5. C# 基础小知识之yield 关键字

    对于yield关键字我们首先看一下msdn的解释: 如果你在语句中使用 yield 关键字,则意味着它在其中出现的方法.运算符或 get 访问器是迭代器. 通过使用 yield 定义迭代器,可在实现自 ...

  6. python2.0 s12 day2

    s12 day2 视频每节的内容 05 python s12 day2 python编码   1.第一句python代码 python 执行代码的过程 文件读到内存 分析内容 编译字节码  转换机器码 ...

  7. shell基础(七)-条件语句

    条件语句在编写脚本经常遇到:用于处理逻辑问题. 一 IF 语句 if 语句通过关系运算符判断表达式的真假来决定执行哪个分支.Shell 有三种 if ... else 语句: if ... fi 语句 ...

  8. 实例:用类来写一个 memcached 启动脚本

    [root@localhost ~]$ yum install -y memcached #!/usr/bin/env python #-*- coding:utf-8 -*- import os i ...

  9. js里面进行位运算时候的注意事项

    &(按位与):两个操作数都是1就是1 任何数与1按位与的出来的都是其二进制最后一位:任何数与0按位与都是0|(按位或):两个操作数一个是1就是1 任何数与0按位或都是其本身^(按位异或):两个 ...

  10. JS-倒计时效果

    团购-限时抢 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...