:: Re: [DNG] How to mount NTFS
Etusivu
Poista viesti
Vastaa
Lähettäjä: g4sra
Päiväys:  
Vastaanottaja: dng
Aihe: Re: [DNG] How to mount NTFS
On 07/08/2020 21:01, Haines Brown wrote:
> On Fri, Aug 07, 2020 at 06:34:04PM +0100, g4sra wrote:
>
>> Post your backup script for others to look over.
>
>
> #!/bin/bash
> a="============================================="
> b="Start: "
> c=$(date)
> mount /mnt/backup &

    ^^^^^^^^^^^^
1) Don't do this in the background, script execution will proceed straight into the 'find' command below before the mount is ready.


2) Ensure you are mounting using 'ntfs-3g' or you will get a large performance hit and unsafe writes (last time I checked the Docs).
E.g. /etc/fstab
/dev/XXX /mnt/backup ntfs-3g defaults 0 0
Or in the script
'ntfs-3g /dev/XXX /mnt/backup

3) abort if the mount fails
[ $? -eq 0 ] || {echo "Mount Failed!"; exit 1;}

> find /mnt/backup/20* -maxdepth 0 -type d | sort -n | head -n 1 | xargs rm -rfv
> sleep 3s
> dirName=`date +%Y.%m.%d`
> mkdir /mnt/backup/"$dirName"
> find / -print | egrep "^/mnt^/var^/mail|^/home|^/etc|^/opt|^/storage|^/info|^/usr/local" | cpio -pdmuv /mnt/backup/"$dirName" 2>&1 | cat -vT
> d="End:"
> e=$(date +%H:%M:%S)
> f="Disk used: "
> g=`df /mnt/backup | tail -n 1 | awk '{print $5}'`
> printf "$a \n $b $c \n $d $e \n $f %s\n" "$g" >> /home/haines/.backup.log



You are backing up files that have not changed since the last backup.
Do you really need all of that kerfuffle ?

As an example I use:

#!/bin/bash -e
# exclude paths are relative to the '/home/user/' source path e.g '/home/user/.cache/'
ionice -c Best-effort -n 7 -t rsync -abv --delete --backup-dir /mnt/backup/history/user.$(date +%Y%m%d%H%M) --exclude='/.cache/*' /home/user/ /mnt/backup/home/user/


You could do worse than read the man page for 'rsync'
Experienced others on the list please chime in and pick up\holes in anything I have missed...