4 Commits
3.2.7 ... 3.3.0

Author SHA1 Message Date
d6d9fbf6e4 Add no-syslog option 2023-06-04 10:16:50 +02:00
ffbf8ece91 Remove last_backup link 2023-06-02 19:38:28 +02:00
6c07c147ae Version bump 2023-06-02 17:04:53 +02:00
5ddd374350 Fix notification bug
Correctly handle exception when trying to display notification if
dbus-python is not available
2023-06-02 17:01:37 +02:00
7 changed files with 40 additions and 47 deletions

View File

@ -20,6 +20,10 @@ The script uses rsync to actually run the backup, so you will have to install it
sudo pacman -Syu rsync sudo pacman -Syu rsync
``` ```
It's also required to have python-dotenv
Optional dependencies are systemd-python to enable using systemd journal for logging, and dbus-python for desktop notifications.
## Install ## Install
To install the program, first clone the repository: To install the program, first clone the repository:
@ -27,23 +31,21 @@ To install the program, first clone the repository:
git clone https://github.com/Fuxino/simple_backup.git git clone https://github.com/Fuxino/simple_backup.git
``` ```
Install tools required to build and install the package: Then install the tools required to build the package:
```bash ```bash
pip install --upgrade build installer wheel pip install --upgrade build wheel
``` ```
Then run: Finally, run:
```bash ```bash
cd simple_backup cd simple_backup
python -m build --wheel python -m build --wheel
python -m installer dist/*.whl python -m pip install dist/*.whl
``` ```
For Arch Linux and Arch-based distros, two packages are available in the AUR (aur.archlinux.org): For Arch Linux and Arch-based distros, two packages are available in the AUR (aur.archlinux.org):
- **simple_backup** for the release version - **simple_backup** for the release version
- **simple_backup-git** for the git version - **simple_backup-git** for the git version
After installing, copy simple_backup.conf (if you used the PKGBUILD on Arch, it will be in /etc/simple_backup/) to $HOME/.config/simple_backup and edit is as needed.

View File

@ -56,6 +56,9 @@ Same as rsync option \(aq\-\-checksum\(aq, use checksums instead of mod\-time an
.B \-\-remove\-before\-backup .B \-\-remove\-before\-backup
Remove old backups (if necessary) before creating the new backup. Useful to free some space before performing the backup. Remove old backups (if necessary) before creating the new backup. Useful to free some space before performing the backup.
Default behavior is to remove old backups after successfully completing the backup. Default behavior is to remove old backups after successfully completing the backup.
.TP
.B \-\-no\-syslog
Don't use systemd journal for logging
.SH CONFIGURATION .SH CONFIGURATION
An example configuration file is provided at \(aq/etc/simple_backup/simple_backup.conf\(aq. Copy it to the default location An example configuration file is provided at \(aq/etc/simple_backup/simple_backup.conf\(aq. Copy it to the default location
($HOME/.config/simple_backup) and edit it as needed. ($HOME/.config/simple_backup) and edit it as needed.

View File

@ -25,7 +25,12 @@ packages = simple_backup
python_requires = >=3.7 python_requires = >=3.7
install_requires = install_requires =
python-dotenv python-dotenv
[options.extras_require]
JOURNAL =
systemd-python systemd-python
NOTIFICATIONS =
dbus-python
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =

View File

@ -1,8 +0,0 @@
post_install() {
echo "An example configuration file is found in /etc/simple_backup/simple_backup.conf."
echo "Copy it to ~/config/simple_backup/simple_backup.conf and modify it as needed"
}
post_upgrade() {
post_install
}

View File

@ -1,3 +1,3 @@
"""Init.""" """Init."""
__version__ = '3.2.7' __version__ = '3.3.0'

View File

@ -125,9 +125,6 @@ class Backup:
except FileNotFoundError: except FileNotFoundError:
return return
if dirs.count('last_backup') > 0:
dirs.remove('last_backup')
n_backup = len(dirs) - 1 n_backup = len(dirs) - 1
count = 0 count = 0
@ -150,14 +147,16 @@ class Backup:
logger.info(f'Removed {count} backups') logger.info(f'Removed {count} backups')
def find_last_backup(self): def find_last_backup(self):
if os.path.islink(f'{self.output}/simple_backup/last_backup'): try:
link = os.readlink(f'{self.output}/simple_backup/last_backup') dirs = sorted([f.path for f in os.scandir(f'{self.output}/simple_backup') if f.is_dir(follow_symlinks=False)])
except FileNotFoundError:
if os.path.isdir(link):
self._last_backup = link
else:
logger.info('No previous backups available') logger.info('No previous backups available')
else:
return
try:
self._last_backup = dirs[-1]
except IndexError:
logger.info('No previous backups available') logger.info('No previous backups available')
# Function to read configuration file # Function to read configuration file
@ -170,8 +169,8 @@ class Backup:
except NameError: except NameError:
pass pass
self.create_backup_dir()
self.find_last_backup() self.find_last_backup()
self.create_backup_dir()
_, self._inputs_path = mkstemp(prefix='tmp_inputs', text=True) _, self._inputs_path = mkstemp(prefix='tmp_inputs', text=True)
_, self._exclude_path = mkstemp(prefix='tmp_exclude', text=True) _, self._exclude_path = mkstemp(prefix='tmp_exclude', text=True)
@ -215,25 +214,6 @@ class Backup:
logger.info(f'rsync: {output[-3]}') logger.info(f'rsync: {output[-3]}')
logger.info(f'rsync: {output[-2]}') logger.info(f'rsync: {output[-2]}')
if os.path.islink(f'{self.output}/simple_backup/last_backup'):
try:
os.remove(f'{self.output}/simple_backup/last_backup')
except FileNotFoundError:
logger.error('Failed to remove last_backup link. File not found')
self._err_flag = True
except PermissionError:
logger.error('Failed to remove last_backup link. Permission denied')
self._err_flag = True
try:
os.symlink(self._output_dir, f'{self.output}/simple_backup/last_backup', target_is_directory=True)
except FileExistsError:
logger.error('Failed to create last_backup link. Link already exists')
self._err_flag = True
except PermissionError:
logger.error('Failed to create last_backup link. Permission denied')
self._err_flag = True
if self.keep != -1 and not self.remove_before: if self.keep != -1 and not self.remove_before:
self.remove_old_backups() self.remove_old_backups()
@ -250,7 +230,10 @@ class Backup:
except NameError: except NameError:
pass pass
else: else:
try:
notify('Backup finished') notify('Backup finished')
except NameError:
pass
def _parse_arguments(): def _parse_arguments():
@ -269,6 +252,7 @@ def _parse_arguments():
help='Use checksum rsync option to compare files (MUCH SLOWER)') help='Use checksum rsync option to compare files (MUCH SLOWER)')
parser.add_argument('--remove-before-backup', action='store_true', parser.add_argument('--remove-before-backup', action='store_true',
help='Remove old backups before executing the backup, instead of after') help='Remove old backups before executing the backup, instead of after')
parser.add_argument('--no-syslog', action='store_true', help='Disable systemd journal logging')
args = parser.parse_args() args = parser.parse_args()
@ -314,6 +298,13 @@ def notify(text):
def simple_backup(): def simple_backup():
args = _parse_arguments() args = _parse_arguments()
if args.no_syslog:
try:
logger.removeHandler(j_handler)
except NameError:
pass
inputs, output, exclude, keep = _read_config(args.config) inputs, output, exclude, keep = _read_config(args.config)
if args.input is not None: if args.input is not None: