laurent22 / rsync-time-backup

Time Machine style backup with rsync.
3.38k stars 446 forks source link

File existence and file system type checks #170

Closed omer-musa-battal closed 4 years ago

omer-musa-battal commented 4 years ago

Added error checking for nonexistent source file. Also added file system type checks for destination and source, rsync flags are updated accordingly. Same edits with #146 , repeated here since the fork seems to be gone.

laurent22 commented 4 years ago

Looks good, thanks @omer-musa-battal!

kapitainsky commented 4 years ago

df -T on macOS.... works quite different as per man df

 -T      Only print out statistics for filesystems of the specified types.  More than one type may be specified in a comma separated list.  The list of
         filesystem types can be prefixed with ``no'' to specify the filesystem types for which action should not be taken.  For example, the df command:

               df -T nonfs,mfs

         lists all filesystems except those of type NFS and MFS.  The lsvfs(1) command can be used to find out the types of filesystems that are available on
         the system.

It means that as it is now does not work on macOS.

df -T msdos on macOS will list fat filesystems attached e.g.:

df -T msdos
Filesystem   512-blocks Used Available Capacity iused ifree %iused  Mounted on
/dev/disk4s1    3901976 1800   3900176     1%       0     0  100%   /Volumes/UNTITLED

and I guess the same logic should be applied to exfat so you need:

df -T msdos,exfat

omer-musa-battal commented 4 years ago

@kapitainsky, could you please try out the latest version of my fork on macOS, and see if it works or not? I do not own a macOS device, but I hope the df command will work now. Thanks in advance.

kapitainsky commented 4 years ago

I looked into your code and can see that it wont work on mac

fn_run_cmd "df -t vfat -t exfat -t fat32 -t fat16 -t fat12 '${1}'"

  1. macOS uses different filesystem names (msdos,exfat)
  2. it does not list filesystem you request by ${1} but list of all filesystems matching criteria
  3. you should not use -t

See this from macOS man:

 -T      Only print out statistics for filesystems of the specified types.  More than one type may be specified in a comma separated list.  The list of
         filesystem types can be prefixed with ``no'' to specify the filesystem types for which action should not be taken.  For example, the df command:

               df -T nonfs,mfs

         lists all filesystems except those of type NFS and MFS.  The lsvfs(1) command can be used to find out the types of filesystems that are available on
         the system.

 -t      If used with no arguments, this option is a no-op (Mac OS X already prints the total allocated-space figures).  If used with an argument, it acts
         like -T, but this usage is deprecated and should not be relied upon.

so on mac it would be rather checking something like that

df -T msdos,exfat | grep ${1}

Long story short at the moment I don't see one solution which would work for both GNU Linux, and macOS. You should also check df behaviour on BSD, FreeBSD systems

kapitainsky commented 4 years ago

this check will have to have two versions, something like this:

if platform is macOS
  check: df -T msdos,exfat | grep ${1}
else
  check:df -t vfat -t exfat -t fat32 -t fat16 -t fat12 '${1}'
kapitainsky commented 4 years ago

look at rsync-time-backup platform depended fn_parse_date() function as an example how to start

https://github.com/laurent22/rsync-time-backup/blob/88db869fe7a52864e18afc7e16a971499f79e830/rsync_tmbackup.sh#L60-L76

kapitainsky commented 4 years ago

here is example of df -T msdos,exfat on macOS:

$ df -T msdos,exfat
Filesystem   512-blocks Used Available Capacity iused ifree %iused  Mounted on
/dev/disk4s1    3901976 1800   3900176     1%       0     0  100%   /Volumes/UNTITLED

with exfat disk mounted. This will print more than one line if more fat disks are mounted.

kapitainsky commented 4 years ago

and I was wrong with $1 parameter, it works

$ df -T apfs
Filesystem   512-blocks      Used Available Capacity iused      ifree %iused  Mounted on
/dev/disk1s5  976695384  21307384 400864176     6%  484009 4882992911    0%   /
/dev/disk1s1  976695384 546719280 400864176    58%  941914 4882535006    0%   /System/Volumes/Data
/dev/disk1s4  976695384   6293584 400864176     2%       4 4883476916    0%   /private/var/vm
/dev/disk3s1  976101344 669502840 306283240    69%   14681 4880492039    0%   /Volumes/DBSamsung-SSD-500

$ df -T apfs /System/Volumes/Data
Filesystem   512-blocks      Used Available Capacity iused      ifree %iused  Mounted on
/dev/disk1s1  976695384 546719272 400864184    58%  941913 4882535007    0%   /System/Volumes/Data
omer-musa-battal commented 4 years ago

I used this as a reference for df on macOS, was not a good idea apparently :)

What happens if no FAT disks are mounted when df -T msdos,exfat ${1} is called? Does it return any error on stderr? If not, I do not have to redirect the command output to be cron friendly.

I updated my fork based on your suggestions, and tested them on GNU Linux. Could I ask you to fix possible errors in fn_df_t() and fn_df_t_src() functions for darwin* cases, since I cannot properly test them? They should output 0 if the disk is not FAT, and >0 otherwise for the later check to work.

Thanks again, and sorry for the mess I caused.

kapitainsky commented 4 years ago

not a big mess. I expect that probably nobody on macOS is backing up to FAT filesystem so 99% it went unnoticed.

it is not so easy to cover all cases:)

I am offline for today but will check tomorrow.

kapitainsky commented 4 years ago

What happens if no FAT disks are mounted when df -T msdos,exfat ${1} is called? Does it return any error on stderr? If not, I do not have to redirect the command output to be cron friendly.

df -T msdos,exfat ${1} returns nothing, no error

I updated my fork based on your suggestions, and tested them on GNU Linux. Could I ask you to fix possible errors in fn_df_t() and fn_df_t_src() functions for darwin* cases, since I cannot properly test them? They should output 0 if the disk is not FAT, and >0 otherwise for the later check to work.

I tested it and they now work correctly on macOS