Skip to content

Commit

Permalink
Fixed and added new things.
Browse files Browse the repository at this point in the history
Discord status update
Automatic every 6 hours after `backup!start`
To stop auto backups do `backup!start`
To start them do `backup!restart` then `backup!start`.
  • Loading branch information
MrRazamataz committed Mar 28, 2021
1 parent 528a394 commit ad93203
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
10 changes: 5 additions & 5 deletions backup_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ def backup_func():
# and directories

hostname = 'ip'
port = 22
username = 'root'
port = 22 #default port for ssh/sftp is 22, change if needed
username = 'user'
password = 'password'
start_directory = 'folder to backup.'
backup_dir = 'backup to'
start_directory = 'dir to backup'
backup_dir = 'dir to save to (on local machine, same that the bot is running on)'

import paramiko
import os
import datetime
Expand Down
8 changes: 4 additions & 4 deletions backup_func2.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def backup_func2():
# and directories

hostname = 'ip'
port = 22
username = 'root'
port = 22 #default port for ssh/sftp is 22, change if needed
username = 'user'
password = 'password'
start_directory = 'folder to backup.'
backup_dir = 'backup to'
start_directory = 'dir to backup'
backup_dir = 'dir to save to (on local machine, same that the bot is running on)'

import paramiko
import os
Expand Down
59 changes: 44 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from discord.ext import commands
from backup_func import *
from backup_func2 import *
import asyncio
global online
online = True
print ("Starting.")
client = commands.Bot(command_prefix="backup!", help_command=None)

Expand All @@ -15,24 +18,50 @@ async def on_ready():
@client.command(name="start")
@commands.has_permissions(administrator=True)
async def start(ctx: commands.Context):
try:
print ("Backup starting.")
await ctx.channel.send("Backup starting.")
#from backup_func import backup_func
backup_func()
except OSError as err:
await ctx.send("First backup complete.")
print ("Backup Complete")
while online == True:
try:
await ctx.send("Starting second backup...")
print ("Second backup starting.")
backup_func2()
await ctx.send("Backup complete.")
print("Backup Complete")
print ("Backup starting.")
await ctx.channel.send("Backup starting.")
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='backing up...'))
#from backup_func import backup_func
backup_func()
except OSError as err:
print(err)
await ctx.send("Backup complete.")
await ctx.send("First backup complete.")
print ("Backup Complete")
try:
await ctx.send("Starting second backup...")
print ("Second backup starting.")
backup_func2()
await ctx.send("Backup complete.")
print("Backup Complete")
await ctx.send("Waiting for next backup to start in 6 hours.")
print ("Waiting for next backup to start in 6 hours.")
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='waiting for next backup. play.kingdomscrusade.net'))
await asyncio.sleep(21600)
except OSError as err:
print(err)
await ctx.send("Backup complete.")
print ("Backup Complete")
await ctx.send("Waiting for next backup to start in 6 hours.")
print ("Waiting for next backup to start in 6 hours.")
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='waiting for next backup. play.kingdomscrusade.net'))
await asyncio.sleep(21600)
@client.command(name="stop")
@commands.has_permissions(administrator=True)
async def stop(ctx: commands.Context):
await ctx.channel.send("Stopping the backup sequence.")
global online
online = False
print ("Backup stopped (paused)")
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='KC Backup Bot 1.0, play.kingdomscrusade.net Backup status: paused'))
@client.command(name="restart")
@commands.has_permissions(administrator=True)
async def restart(ctx: commands.Context):
await ctx.channel.send("Restarting the backup sequence (you need to run backup!start to set it auto going again).")
global online
online = True
print("Backup started (unpaused)")
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='Restarting backups.'))
@client.event
async def on_error(ctx, event, *args, **kwargs):
if isinstance(FileNotFoundError):
Expand Down

0 comments on commit ad93203

Please sign in to comment.