Soldato
I'm working on a backup script for my satellite server.
Red Hat provide a script which I have modified.
My issue is the following.
The script will run as root (I suppose)
I need to mount and unmount an nfs share.
Then sudo su to a user that has write permissions (nfsuser) on the share then run the satellite-backup command then exit as nfsuser back to root and umount the nfs share.
The problem is the satellite-backup command seems to need to run as root, but at this point I am currently in as nfsuser:
#!/bin/bash -e
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESTINATION=/backups/satellite_backup
YEAR=$(date +%Y)
WEEK=$(date +%-V)
mount nfsshareserver:/backup /backups
sudo su nfsuser
if [[ $(date +%w) == 0 ]]; then
satellite-backup $DESTINATION/$YEAR-$((WEEK + 1)) --assumeyes
else
LAST=$(ls -td -- $DESTINATION/$YEAR-$WEEK/*/ | head -n 1)
satellite-backup $DESTINATION/$YEAR-$WEEK --incremental "$LAST" --assumeyes
fi
exit 0
exit
umount /backups
How do I make the satellte-backup command run as root. The issue is only the nfsuser can write to the nfs share.
Red Hat provide a script which I have modified.
My issue is the following.
The script will run as root (I suppose)
I need to mount and unmount an nfs share.
Then sudo su to a user that has write permissions (nfsuser) on the share then run the satellite-backup command then exit as nfsuser back to root and umount the nfs share.
The problem is the satellite-backup command seems to need to run as root, but at this point I am currently in as nfsuser:
#!/bin/bash -e
export PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESTINATION=/backups/satellite_backup
YEAR=$(date +%Y)
WEEK=$(date +%-V)
mount nfsshareserver:/backup /backups
sudo su nfsuser
if [[ $(date +%w) == 0 ]]; then
satellite-backup $DESTINATION/$YEAR-$((WEEK + 1)) --assumeyes
else
LAST=$(ls -td -- $DESTINATION/$YEAR-$WEEK/*/ | head -n 1)
satellite-backup $DESTINATION/$YEAR-$WEEK --incremental "$LAST" --assumeyes
fi
exit 0
exit
umount /backups
How do I make the satellte-backup command run as root. The issue is only the nfsuser can write to the nfs share.
Last edited: