标签:shell

0

217

有关nas私有云的一些备份操作(shell)笔记

场景一:备份电脑资料

将电脑中的某一文件(文件夹)备份到 nas 去,思路如下:

1、在本地电脑挂载 nassamba 共享目录;

2、通过 rsync 同步命令,增量备份 的方式同步到上述挂载的 samba 共享目录下;

具体 shell 脚本如下:

#!/bin/bash

if [ ! -d /mnt/xiao/photo ]; then
    echo "mount samba dir from 192.168.2.200"
    mount -t cifs //192.168.2.200/xiao /mnt/xiao -o user=xiao,password=12345678,rw,file_mode=0777,dir_mode=0777
fi

if [ -d /mnt/xiao/photo ]; then
    echo "rsync photo ..."
    rsync -auv --exclude='.cache/' --exclude='.*' /data/photo /mnt/xiao/
fi

注以上脚本依赖 cifs-utils 类库,ubuntu 先安装 :

sudo apt install cifs-utils

场景二:备份苹果手机照片

苹果系统从 ios 11 版本以后的照片是 .HEIC 格式,备份思路如下:

1、先从手机中整体将照片拷贝出来:按相片的创建时间,按 年份/月份 归整 cp 到指定的文件夹下;

2、拷贝的过程中,如果文件名是.HEIC 格式,则附加一项 格式转换 的脚本任务,将.HEIC 格式转换成 .JPG 格式;

3、格式转换后,用 touch 命令将生成的.JPG 格式文件的创建时间属性保留与 .HEIC 格式源文件相同;

具体 shell 脚本如下:

……

乐果   发表于   2023 年 12 月 12 日 标签:shell 继续阅读

0

2367

平时编写的一些shell脚步例举笔记

批量杀死进程
ps -ef|grep test.sh
xiao      3296 28517  0 10:09 pts/3    00:00:06 /bin/bash ./test.sh
xiao      3365 28517  0 10:09 pts/3    00:00:06 /bin/bash ./test.sh
xiao      3401 28517  0 10:09 pts/3    00:00:06 /bin/bash ./test.sh
xiao      3443 28517  0 10:09 pts/3    00:00:06 /bin/bash ./test.sh
xiao      3480 28517  0 10:09 pts/3    00:00:06 /bin/bash ./test.sh
xiao      5299 28517  0 10:10 pts/3    00:00:06 /bin/bash ./test.sh
xiao      5396 28517  0 10:10 pts/3    00:00:06 /bin/bash ./test.sh
xiao      5431 28517  0 10:10 pts/3    00:00:06 /bin/bash ./test.sh
xiao      5470 28517  0 10:10 pts/3    00:00:06 /bin/bash ./test.sh
xiao      5488 28517  0 10:10 pts/3    00:00:06 /bin/bash ./test.sh
xiao      6589 28517  0 10:33 pts/3    00:00:05 /bin/bash ./test.sh
xiao      6754 28517  0 10:33 pts/3    00:00:05 /bin/bash ./test.sh
xiao      6899 28517  0 10:33 pts/3    00:00:05 /bin/bash ./test.sh
xiao      6972 28517  0 10:33 pts/3    00:00:05 /bin/bash ./test.sh
xiao      7015 28517  0 10:33 pts/3    00:00:05 /bin/bash ./test.sh
xiao      7095 28517  0 10:33 pts/3    00:00:05 /bin/bash ./test.sh
xiao      7129 28517  0 10:33 pts/3    00:00:05 /bin/bash ./test.sh
xiao      7172 28517  0 10:33 pts/3    00:00:05 /bin/bash ./test.sh


ps -ef|grep test.sh|awk '{print "kill -9 " $2}'|sh
服务启动、重启、停止

一个服务的启动、重启、停止的shell脚步:

……

乐果   发表于   2018 年 09 月 06 日 标签:shell 继续阅读

0

2558

ubuntu下ssh链接shell脚本---expect

一、安装expect

sudo apt-get install expect

二、shell脚本文件,例:

#!/usr/bin/expect -f
set port 22
set user root
set host 120.24.165.125
set password *******
set timeout -1
spawn ssh $user@$host
expect "*assword:*"
send "$password\r"
interact
#expect eof

乐果   发表于   2015 年 08 月 09 日 标签:ubuntushell 继续阅读

0

2560

svn钩子同步代码

shell代码如下:

#!/bin/sh
export LANG=en_US.UTF-8
PATH=/usr/bin
SVN=$PATH/svn
SVN_LOGIN_INFO="--username ***** --password ********"
#SVN_LOG=/var/log/svn/${DATE}-svn.log
SVN_SRC=/opt/code_src/shop-yun/
WEB_SRC=/opt/www-data/shop-yun/
RSYNC=/$PATH/rsync
DATE=`/bin/date +%Y%m%d`

# svn update
${SVN} update ${SVN_LOGIN_INFO} ${SVN_SRC}

# rsync to web from src
${RSYNC} -aH --delete --progress --exclude=".svn/,conf/app.ini" ${SVN_SRC} ${WEB_SRC} >> /var/log/rsync-self.log.$DATE
/bin/chown -R www-data:www-data ${WEB_SRC}
${RSYNC} -avzuP  --exclude-from=/opt/code/shop-yun/hooks/rsync_admin_list.conf  ${WEB_SRC}  root@63.***.**.**::website  >> /var/log/rsync-svn.log.$DATE

乐果   发表于   2014 年 11 月 14 日 标签:shellsvn 继续阅读

热评文章