20200428_在centos7.2上挂载ntfs和备份文件到移动硬盘

[root@localhost ~]# fdisk -l

磁盘 /dev/sda:2000.4 GB, 2000398934016 字节,3907029168 个扇区
…

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200  3907028991  1952464896   8e  Linux LVM

…


磁盘 /dev/sdb:2000.4 GB, 2000398931968 字节,3907029164 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0007b1e1

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  3907026943  1953512448    7  HPFS/NTFS/exFAT
[root@localhost ~]# mkdir /mnt/yidongyingpan
[root@localhost ~]# mount /dev/sdb1 /mnt/yidongyingpan/
mount: 未知的文件系统类型“ntfs”
[root@localhost ~]# gcc -v
-bash: gcc: 未找到命令 
#安装gcc
[root@localhost ~]#  yum -y install gcc
#下载ntfs-3g
[root@localhost ~]# wget http://tuxera.com/opensource/ntfs-3g_ntfsprogs-2013.1.13.tgz
#解压文件:
[root@localhost ~]# tar -xvf ntfs-3g_ntfsprogs-2013.1.13.tgz
#检测环境:
[root@localhost ~]# cd ntfs-3g_ntfsprogs-2013.1.13
[root@localhost ntfs-3g_ntfsprogs-2013.1.13]#  ./configure
…
You can type now 'make' to build ntfs-3g.
#打包并安装
[root@localhost ntfs-3g_ntfsprogs-2013.1.13]# make && make install

#mkn 两次tab看看命令, 有mknod   mkntfs两个命令, 说明是可以了
[root@localhost ntfs-3g_ntfsprogs-2013.1.13]# mkn
mknod   mkntfs
#创建挂载目录, 给目录起一个NB的名字, 挂载NTFS盘:
[root@localhost ~]# mkdir /mnt/yidongyingpan/
#卸载移动硬盘, /dev/sdb1就是上面fdisk –l出来的内容
#[root@localhost ~]#  umount /dev/sdb1 
[root@localhost ~]# ls /mnt/yidongyingpan/
#开始挂载
[root@localhost ~]# mount -t ntfs-3g /dev/sdb1 /mnt/yidongyingpan/ 
[root@localhost ~]#df –h #查看挂载
[root@localhost ~]# ls /mnt/yidongyingpan/

 

#设置开机自动挂载
[root@localhost ~]# vim /etc/fstab

 

 

#开始备份指定文件夹到移动硬盘 

[root@localhost ~]# vim dirback2yd.sh

#!/bin/bash

# Name: dirback2yd.sh
# Description: copy home and opt dir files
# Author:wxy
# Datetime: 2020-04-27 21:51:29

dirname=$(date "+%Y%m%d%H%M%S")
#dirtar=/mnt/yidongyingpan/$dirname/
dirhome=/mnt/yidongyingpan/$dirname/home/
diropt=/mnt/yidongyingpan/$dirname/opt/

#rm -rf $dirname/home
#mkdir -p $dirtar
mkdir -p  $dirhome
mkdir -p  $diropt
#cd $dirtar

#tar -zcvf $dirtar/home.tar.gz /home/
#tar -zcvf $dirtar/home.tar.gz /opt/

tar -cvzf - /home | split -d -b 1024m - $dirhome/home.tar.gz
tar -cvzf - /opt | split -d -b 1024m - $diropt/opt.tar.gz

cat $dirhome/home.tar.gz* > $dirhome/home.tar.gz
#删除合并前的文件
rm -f $dirhome/home.tar.gz?*

cat $diropt/opt.tar.gz* > $diropt/opt.tar.gz
rm -f $diropt/opt.tar.gz?*

#cp -a -f /home/*  $dirhome
#cp -a -f /opt/* $diropt
#删除3天前的目录
find /mnt/yidongyingpan/   -atime +3   -name "2020*"    -type d -exec rm -rf {} \;

echo "$dirname"

#创建定时任务, 使其每天执行:

[root@localhost ~]#  crontab –e

0 4 * * * /root/dirback2yd.sh   #每天4点执行一次

 

posted on 2020-04-28 08:46  印子  阅读(411)  评论(0编辑  收藏  举报

导航