Solved backup script not copying over some sys files (conf)

I made this script to backup my systems and On Fbsd it is not copying over certian conf files leaving them empty. how to fix that, anyone?

Code:
#!/usr/bin/env bash

if [[ -f /etc/slackware-version ]] ; then
    distroname=$(sed 's/Slackware /Slackware-/' /etc/slackware-version)
elif [[ "FreeBSD" =~ "$( awk 'NR==1{print $1}' /etc/*release | cut -d = -f2 | xargs)" ]] ; then
    distroname="$(uname -a | awk '{print $1 "-" $3}')"
else
    distroname=$( awk 'NR==1{print $1}' /etc/*release | cut -d = -f2 | xargs)
fi
sorce="$HOME"
dest="/media/storage/HomeBackUps/$distroname/"
if [[ -d /media/storage ]] ; then 
    mkdir -pv "$dest"
else
    echo "directory /media/storage not present .. exiting..."
    exit
fi

echo "$distroname
$dest"
 
if [[ "$distroname"  =~ "FreeBSD" ]] ; then
    mkdir -p $dest
    mkdir -p $dest/boot
    sudo cp -v /boot/loader.conf $dest/boot
    sudo cp -v /boot/device.hints /$dest/boot
    mkdir -p $dest/etc 
    sudo cp -v /etc/rc.conf $dest/etc
    sudo cp -v /etc/sysctl.conf $dest/etc
    mkdir -p $dest/usr/local/etc
    sudo cp -v /usr/local/etc/sudoers $dest/usr/local/etc
    mkdir -pv $dest/etc/bluetooth
    sudo cp -v /etc/bluetooth/hcsecd.conf $dest/etc/bluetooth
    sudo cp -v /etc/bluetooth/hosts $dest/etc/bluetooth
    
fi

rsync -a --info=progress --exclude="lost+found" --exclude=".cache" --exclude="snap" --exclude=".dbus" "$sorce" "$dest"
using sudo for root permissions still does not work.
hcsecd.conf is the one that is not being copied over properly (for now).
 
I don't know why you get some zero-length files out of this.

But I recommend that you either check out rsync for this (which doesn't leave half-baked files around).

Or use tar for that kind of partial directory structure copying.

Myself I update all of /etc and /usr/local/etc in a script like this since it is small enough to not be a burden. Well, Linux can have a much bigger /etc than FreeBSD but still.
 
I don't know why you get some zero-length files out of this.

But I recommend that you either check out rsync for this (which doesn't leave half-baked files around).
the bottom line is rsync for my home dirs.

Code:
userx@FreeBeSD:~$ file /etc/bluetooth/hcsecd.conf
/etc/bluetooth/hcsecd.conf: regular file, no read permission

 ls -la /etc/bluetooth/hcsecd.conf
-rw-------  1 root  wheel  1445 Apr  9 09:47 /etc/bluetooth/hcsecd.conf



userx@FreeBeSD:~$ file /etc/bluetooth/hosts
/etc/bluetooth/hosts: ASCII text

$ ls -la /etc/bluetooth/hosts
-rw-r--r--  1 root  wheel  312 Apr  9 09:45 /etc/bluetooth/hosts
no read permission might have something to do with it.

would it be prudent to change permissions on that file?
 
No. Obviously the script (or parts of it) should run as a user that is in a group that you give group read permission for.
which is wheel but only the owner has rw permissions

ls -la /etc/bluetooth/hcsecd.conf
-rw------- 1 root wheel 1445 Apr 9 09:47 /etc/bluetooth/hcsecd.conf

$groups
userx wheel operator video

even though I can edit it

sudo ee /etc/bluetooth/hcsecd.conf
 
What I am saying is that I would make a new group and a new user (in that group).

Okay I found it, I booted to my RC install, copied that file to my home dir which worked, then investigated the backup dirs.

Code:
sudo chown -R userx:userx /media/storage/HomeBackUps/FreeBSD-13.2-RC6/etc
userx@FBSD13-2RC6:~$ ls -la /media/storage/HomeBackUps/FreeBSD-13.2-RC6
total 48
drwxr-xr-x   6 userx  100    4096 Apr  7 08:47 .
drwxrwxr-x  10 userx  100    4096 Apr  8 06:53 ..
drwxr-xr-x   2 userx  100    4096 Apr  7 08:47 boot
drwxr-xr-x   3 userx  userx  4096 Apr  9 11:26 etc
drwxr-xr-x  23 userx  userx  4096 Apr  9 11:24 userx
drwxr-xr-x   3 userx  100    4096 Apr  7 08:47 usr
they have users group attached to them UID 100 from linux . So yeah I do suppose I can create a users group UID 100 then make that my user main group that should elevate jumping between linux and FreeBSD permissions those system side dirs. though linux should not be touching them due to how it is setup in the script, they must have been created before I put that check in the script.

so let me chown group to them all then try it out to see if linux messes them up first.

thanks for the idea.
 
Back
Top