Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bmc: sync-once: handle deleted source files
Ensure destination files are removed if the source files are deleted. Two changes are made to the sync-once script: 1. If the sync entry is not present in the source, remove it from the destination. 2. Add --delete option to rsync to remove destination files that are not present in the source. Tested For first change: 1. For directories that not present in the source, the destination directory is present. ``` ~# tree /etc/systemd/network/ /etc/systemd/network/ [error opening dir] ~# tree /run/media/rwfs-alt/cow/etc/systemd/network/ /run/media/rwfs-alt/cow/etc/systemd/network/ |-- a |-- b `-- c ``` 2. After running the sync-once script, the destination directory is removed. ``` ~# bash bmc/sync-once.sh rsync -a -R --delete /etc/hostname /run/media/rwfs-alt/cow rsync -a -R --delete /etc/machine-id /run/media/rwfs-alt/cow Removing /run/media/rwfs-alt/cow//etc/systemd/network/ ~# tree /run/media/rwfs-alt/cow/etc/systemd/network/ /run/media/rwfs-alt/cow/etc/systemd/network/ [error opening dir] ``` 3. For files that are not present in the source, the destination file is present. ``` ~# ls -l /etc/machine-id ls: cannot access '/etc/machine-id': No such file or directory ~# ls -l /run/media/rwfs-alt/cow/etc/machine-id -rw-r--r-- 1 root root 33 Feb 14 03:57 /run/media/rwfs-alt/cow/etc/machine-id ``` 4. After running the sync-once script, the destination file is removed. ``` ~# bash bmc/sync-once.sh sudo bash bmc/sync-once.sh ~# rsync -a -R --delete /etc/hostname /run/media/rwfs-alt/cow Removing /run/media/rwfs-alt/cow//etc/machine-id ~# ls -l /run/media/rwfs-alt/cow/etc/machine-id ls: cannot access '/run/media/rwfs-alt/cow/etc/machine-id': No such file or directory ``` For the second change: 1. if the destination is directory and the destination's files are not present in the source, the destination files are removed. ``` ~# tree /etc/systemd/network/ /etc/systemd/network/ |-- a `-- c ~# tree /run/media/rwfs-alt/cow/etc/systemd/network/ /run/media/rwfs-alt/cow/etc/systemd/network/ |-- a |-- b `-- c ~# bash bmc/sync-once.sh rsync -a -R --delete /etc/systemd/network/ /run/media/rwfs-alt/cow ~# tree /etc/systemd/network/ /etc/systemd/network/ |-- a `-- c ~# tree /run/media/rwfs-alt/cow/etc/systemd/network/ /run/media/rwfs-alt/cow/etc/systemd/network/ |-- a `-- c ``` Change-Id: I81f5adcf1816f1c8d0b153fa2ae4db2860daa43a Signed-off-by: Jian Zhang <[email protected]>
- Loading branch information